#endif
};
-struct unsafe_opt_s {
- const char *arg;
+/* A {string,length} tuple, to avoid computing strlen() on constants.
+ * - str must be a \0-terminated string
+ * - len does not account for the terminating '\0'
+ */
+struct str_len_s {
+ const char *str;
size_t len;
};
+/* Define a {string,length} tuple. Takes an unquoted constant string as
+ * parameter. sizeof() on a string literal includes the terminating \0,
+ * but we don't want to count it.
+ */
+#define STR_LEN(s) { #s, sizeof(#s)-1 }
+
/* Unsafe options are options that specify a potentialy unsafe path,
* that will be checked by check_unsafe_path(), below.
- *
- * sizeof() on a string literal includes the terminating \0.
*/
-#define UNSAFE_OPT(o) { #o, sizeof(#o)-1 }
-static const struct unsafe_opt_s unsafe_opts[] = {
- UNSAFE_OPT(-I),
- UNSAFE_OPT(-idirafter),
- UNSAFE_OPT(-iquote),
- UNSAFE_OPT(-isystem),
- UNSAFE_OPT(-L),
+static const struct str_len_s unsafe_opts[] = {
+ STR_LEN(-I),
+ STR_LEN(-idirafter),
+ STR_LEN(-iquote),
+ STR_LEN(-isystem),
+ STR_LEN(-L),
{ NULL, 0 },
};
/* Check for unsafe library and header paths */
for (i = 1; i < argc; i++) {
- const struct unsafe_opt_s *opt;
- for (opt=unsafe_opts; opt->arg; opt++ ) {
+ const struct str_len_s *opt;
+ for (opt=unsafe_opts; opt->str; opt++ ) {
/* Skip any non-unsafe option. */
- if (strncmp(argv[i], opt->arg, opt->len))
+ if (strncmp(argv[i], opt->str, opt->len))
continue;
/* Handle both cases: