mirror of
https://github.com/motioneye-project/motioneyeos.git
synced 2025-07-29 06:06:32 +00:00
toolchain/wrapper: make the {str, len} tuple more generic, add comments
In 61cb120 (toolchain/wrapper: extend paranoid check to -isystem), we introduced a {str,len} tuple to check the various arguments passed to gcc, to avoid hard-coding an ever-growing, long list of those args directly in the condition check. It was made specific to the arguments (the structure member is named 'arg'), but can also be used to store the unsafe paths as well. Also, that piece is almost un-documented. Rename the structure member so that it is more generic, and add a bit of comments to explain the whole of it. Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr> Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
This commit is contained in:
parent
860020f300
commit
31c093e6d0
@ -83,23 +83,30 @@ static char *predef_args[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct unsafe_opt_s {
|
/* A {string,length} tuple, to avoid computing strlen() on constants.
|
||||||
const char *arg;
|
* - 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;
|
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,
|
/* Unsafe options are options that specify a potentialy unsafe path,
|
||||||
* that will be checked by check_unsafe_path(), below.
|
* 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 str_len_s unsafe_opts[] = {
|
||||||
static const struct unsafe_opt_s unsafe_opts[] = {
|
STR_LEN(-I),
|
||||||
UNSAFE_OPT(-I),
|
STR_LEN(-idirafter),
|
||||||
UNSAFE_OPT(-idirafter),
|
STR_LEN(-iquote),
|
||||||
UNSAFE_OPT(-iquote),
|
STR_LEN(-isystem),
|
||||||
UNSAFE_OPT(-isystem),
|
STR_LEN(-L),
|
||||||
UNSAFE_OPT(-L),
|
|
||||||
{ NULL, 0 },
|
{ NULL, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -262,10 +269,10 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Check for unsafe library and header paths */
|
/* Check for unsafe library and header paths */
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
const struct unsafe_opt_s *opt;
|
const struct str_len_s *opt;
|
||||||
for (opt=unsafe_opts; opt->arg; opt++ ) {
|
for (opt=unsafe_opts; opt->str; opt++ ) {
|
||||||
/* Skip any non-unsafe option. */
|
/* Skip any non-unsafe option. */
|
||||||
if (strncmp(argv[i], opt->arg, opt->len))
|
if (strncmp(argv[i], opt->str, opt->len))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Handle both cases:
|
/* Handle both cases:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user