aboutsummaryrefslogtreecommitdiff
path: root/buffer.h
diff options
context:
space:
mode:
authorjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-07-23 19:51:27 +0000
committerjames <james@e7ae566f-a301-0410-adde-c780ea21d3b5>2008-07-23 19:51:27 +0000
commit26bb4c740b12cf3f606f657103a1695c23f6b72f (patch)
tree9d434ae8fd10df3cc42d68539a75409310678160 /buffer.h
parentbuf_printf will now return false on errors, such as truncation (diff)
downloadopenvpn-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 '')
-rw-r--r--buffer.h33
1 files changed, 33 insertions, 0 deletions
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
@@ -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
*/