diff options
author | Michal Domonkos <mdomonko@redhat.com> | 2022-09-26 16:31:29 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2022-10-04 10:11:32 +0300 |
commit | 055734eb2a0f9fe4dd275c71288cd61828d26f81 (patch) | |
tree | 2c77a0967e81c470e7dae45184ad8e6312d313ac /build | |
parent | 2cdbf4af0bae4fc6a343e360089fadc77e17f973 (diff) | |
download | rpm-055734eb2a0f9fe4dd275c71288cd61828d26f81.tar.gz |
Check for missing quote in %files
This check won't hurt, in fact, the quotes param will come in handy in
the next commit.
Only enforce a closing quote, not an opening one, since that would
invalidate filenames with a quote somewhere in the middle, which might
break existing spec files that rely on this quirk. In other words, a
quote that's not the very first char of a filename is still considered
literal, for better or worse.
Diffstat (limited to 'build')
-rw-r--r-- | build/files.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/build/files.c b/build/files.c index 503cf4194..c5c96e0fa 100644 --- a/build/files.c +++ b/build/files.c @@ -238,10 +238,11 @@ static void FileEntryFree(FileEntry entry) /** * strtokWithQuotes. - * @param s - * @param delim + * @param s string to tokenize + * @param delim delimiter chars + * @param[out] quotes 0 if unquoted, 1 if missing quote, 2 if quoted */ -static char *strtokWithQuotes(char *s, const char *delim) +static char *strtokWithQuotes(char *s, const char *delim, int *quotes) { static char *olds = NULL; char *token; @@ -257,7 +258,9 @@ static char *strtokWithQuotes(char *s, const char *delim) return NULL; /* Leading quote escapes original delim until next quote */ + *quotes = 0; if (*s == '"') { + *quotes = 1; delim = "\""; s++; } @@ -277,6 +280,8 @@ static char *strtokWithQuotes(char *s, const char *delim) olds = s; } else { /* Terminate the token and make olds point past it */ + if (*s == '"' && *quotes) + *quotes = 2; *s = '\0'; olds = s+1; } @@ -884,14 +889,21 @@ static rpmRC parseForSimple(char * buf, FileEntry cur, ARGV_t * fileNames) { char *s, *t, *end; char *delim = " \t\n"; + int quotes = 0; rpmRC res = RPMRC_OK; int allow_relative = (RPMFILE_PUBKEY|RPMFILE_DOC|RPMFILE_LICENSE); t = buf; - while ((s = strtokWithQuotes(t, delim)) != NULL) { + while ((s = strtokWithQuotes(t, delim, "es)) != NULL) { t = NULL; end = s + strlen(s) - 1; + /* Syntax checks */ + if (quotes == 1) { + rpmlog(RPMLOG_ERR, _("Missing quote: %s\n"), s); + res = RPMRC_FAIL; + break; + } if (*end == '\n') { /* Newline escaping is not supported */ rpmlog(RPMLOG_ERR, _("Trailing backslash: %s\n"), s); |