|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SOA World Conference
Virtualization Conference $50 Savings Expire June 24, 2008... – Register Today!
SYS-CON.TV SYS-CON.TV WEBCASTS |
TOP LINKS YOU MUST CLICK ON Security
Variadic Functions: How They Contribute To Security Vulnerabilities and How To Fix Them
Variadic functions are implemented using either the ANSI C stdarg approach or, historically, the UNIX System V vararg approach
By: Robert Seacord
Dec. 6, 2005 03:15 PM
Digg This!
Page 2 of 2
« previous page
One solution that is supported by existing C language standards is for the C language compiler to pass a byte count. The VAX standard calling sequence (partially implemented in its hardware instructions) did pass a count of the number of long words making up the argument list. This was carried over into Alpha, and HP VMS for Alpha still does this. If byte count were passed, the va_arg() macro (which currently returns the next argument and increments the argument pointer based on the size of the argument) could also decrement the count and force a runtime-constraint violation when a variadic function attempts to access more arguments than have actually been provided. While the C Standard allows compiler implementations to pass a byte count for variadic functions and not for normal functions, most implementations do not provide a different calling sequence for variadic functions. A common reason to do so is to preserve compatibility between normal and variadic calls. Unfortunately, it's unreasonable to modify the C language specification to require a byte count, as this change would break binary compatibility between existing applications and libraries. However, it might be possible to introduce a new syntax that could be used to enable the compiler to pass a byte count. So, for example, instead of: int printf(const char *format, ...) { } we might have: int safe_printf(const char *format, argc+...); { } or some other, similar syntax.
Type Safety It may be possible to add type safety to variadic functions by placing argument list signatures into symbol tables, for example. It is well within the state of the art to generate code that creates a list of argument types and to generate versions of variadic functions that examine the expected argument type and the actual argument type and generate a runtime error if it finds an unsafe or insecure mismatch. The biggest drawback of this approach is that it might introduce considerable overhead in processing variadic function calls.
Summary and Conclusion
Acknowledgments Page 2 of 2 « previous page
LATEST LINUX STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||