From 26bb4c740b12cf3f606f657103a1695c23f6b72f Mon Sep 17 00:00:00 2001 From: james Date: Wed, 23 Jul 2008 19:51:27 +0000 Subject: Added argv_x functions to buffer.[ch] to be used to safely build up argv strings for execve without the possibility of truncation or misinterpretation of mid-argument spacing. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@3107 e7ae566f-a301-0410-adde-c780ea21d3b5 --- buffer.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'buffer.h') diff --git a/buffer.h b/buffer.h index 7de3363..3190229 100644 --- a/buffer.h +++ b/buffer.h @@ -56,6 +56,12 @@ struct buffer #endif }; +/* used by argv_x functions */ +struct argv { + size_t argc; + char **argv; +}; + /* for garbage collection */ struct gc_entry @@ -221,6 +227,33 @@ int openvpn_snprintf(char *str, size_t size, const char *format, ...) #endif ; +/* + * A printf-like function (that only recognizes a subset of standard printf + * format operators) that prints arguments to an argv list instead + * of a standard string. This is used to build up argv arrays for passing + * to execve. + */ +void argv_init (struct argv *a); +void argv_reset (struct argv *a); +size_t argv_argc (const char *format); +char *argv_term (const char **f); +const char *argv_str (const struct argv *a, struct gc_arena *gc, const unsigned int flags); + +#define APA_CAT (1<<0) /* concatentate onto existing struct argv list */ +void argv_printf_arglist (struct argv *a, const char *format, const unsigned int flags, va_list arglist); + +void argv_printf (struct argv *a, const char *format, ...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + ; + +void argv_printf_cat (struct argv *a, const char *format, ...) +#ifdef __GNUC__ + __attribute__ ((format (printf, 2, 3))) +#endif + ; + /* * remove/add trailing characters */ -- cgit