diff options
author | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2008-07-23 19:51:27 +0000 |
---|---|---|
committer | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2008-07-23 19:51:27 +0000 |
commit | 26bb4c740b12cf3f606f657103a1695c23f6b72f (patch) | |
tree | 9d434ae8fd10df3cc42d68539a75409310678160 /buffer.h | |
parent | buf_printf will now return false on errors, such as truncation (diff) | |
download | openvpn-26bb4c740b12cf3f606f657103a1695c23f6b72f.tar.xz |
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
Diffstat (limited to 'buffer.h')
-rw-r--r-- | buffer.h | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -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 @@ -222,6 +228,33 @@ int openvpn_snprintf(char *str, size_t size, const char *format, ...) ; /* + * 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 */ |