diff options
-rw-r--r-- | build/files.c | 22 | ||||
-rw-r--r-- | include/rpm/rpmfileutil.h | 7 | ||||
-rw-r--r-- | rpmio/rpmfileutil.c | 18 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/data/SPECS/badescape.spec | 19 | ||||
-rw-r--r-- | tests/data/SPECS/globesctest.spec | 16 | ||||
-rw-r--r-- | tests/rpmbuild.at | 26 |
7 files changed, 104 insertions, 5 deletions
diff --git a/build/files.c b/build/files.c index 79dd9d84c..503cf4194 100644 --- a/build/files.c +++ b/build/files.c @@ -264,8 +264,12 @@ static char *strtokWithQuotes(char *s, const char *delim) /* Find the end of the token. */ token = s; - while (!strchr(delim, *s)) - s++; + while (!strchr(delim, *s)) { + if (*s == '\\') + s++; + if (*s != '\0') + s++; + } /* Terminate it */ if (*s == '\0') { @@ -878,13 +882,22 @@ static VFA_t const virtualAttrs[] = { */ static rpmRC parseForSimple(char * buf, FileEntry cur, ARGV_t * fileNames) { - char *s, *t; + char *s, *t, *end; + char *delim = " \t\n"; rpmRC res = RPMRC_OK; int allow_relative = (RPMFILE_PUBKEY|RPMFILE_DOC|RPMFILE_LICENSE); t = buf; - while ((s = strtokWithQuotes(t, " \t\n")) != NULL) { + while ((s = strtokWithQuotes(t, delim)) != NULL) { t = NULL; + end = s + strlen(s) - 1; + + if (*end == '\n') { + /* Newline escaping is not supported */ + rpmlog(RPMLOG_ERR, _("Trailing backslash: %s\n"), s); + res = RPMRC_FAIL; + break; + } /* Set flags for virtual file attributes */ if (vfaMatch(virtualAttrs, s, &(cur->attrFlags))) @@ -901,6 +914,7 @@ static rpmRC parseForSimple(char * buf, FileEntry cur, ARGV_t * fileNames) if (cur->attrFlags & (RPMFILE_DOC | RPMFILE_LICENSE)) cur->attrFlags |= RPMFILE_SPECIALDIR; } + rpmUnescape(s, delim); argvAdd(fileNames, s); } diff --git a/include/rpm/rpmfileutil.h b/include/rpm/rpmfileutil.h index a2396d494..9d195e020 100644 --- a/include/rpm/rpmfileutil.h +++ b/include/rpm/rpmfileutil.h @@ -145,6 +145,13 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr); char * rpmEscapeSpaces(const char * s); /** \ingroup rpmfileutil + * Unescape each char listed in accept by removing a backslash preceding it. + * @param s string + * @param accept chars to unescape (NULL for all) + */ +void rpmUnescape(char *s, const char *accept); + +/** \ingroup rpmfileutil * Return type of compression used in file. * @param file name of file * @param[out] compressed address of compression type diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index d7cfa2f85..bcb61d105 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -404,6 +404,24 @@ char * rpmEscapeSpaces(const char * s) return t; } +void rpmUnescape(char *s, const char *accept) +{ + char *p, *q; + int skip = 0; + + p = q = s; + while (*q != '\0') { + *p = *q++; + if (*p == '\\' && (!accept || strchr(accept, *q)) && !skip) { + skip = 1; + continue; + } + p++; + skip = 0; + } + *p = '\0'; +} + int rpmFileHasSuffix(const char *path, const char *suffix) { size_t plen = strlen(path); diff --git a/tests/Makefile.am b/tests/Makefile.am index 3fb085698..17b0f0f14 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -65,6 +65,7 @@ EXTRA_DIST += data/SPECS/hello-sources.spec EXTRA_DIST += data/SPECS/foo.spec EXTRA_DIST += data/SPECS/globtest.spec EXTRA_DIST += data/SPECS/globesctest.spec +EXTRA_DIST += data/SPECS/badescape.spec EXTRA_DIST += data/SPECS/versiontest.spec EXTRA_DIST += data/SPECS/conflicttest.spec EXTRA_DIST += data/SPECS/configtest.spec diff --git a/tests/data/SPECS/badescape.spec b/tests/data/SPECS/badescape.spec new file mode 100644 index 000000000..3e09e8046 --- /dev/null +++ b/tests/data/SPECS/badescape.spec @@ -0,0 +1,19 @@ +Name: badescape +Version: 1.0 +Release: 1 +Summary: Testing trailing backslash in filename +Group: Testing +License: GPL +BuildArch: noarch + +%description +%{summary}. + + +%build + +%install + +%files +/opt/foo\ + diff --git a/tests/data/SPECS/globesctest.spec b/tests/data/SPECS/globesctest.spec index 6141159ce..04e93f589 100644 --- a/tests/data/SPECS/globesctest.spec +++ b/tests/data/SPECS/globesctest.spec @@ -17,6 +17,7 @@ BuildArch: noarch %build touch 'foo[bar]' bar baz 'foo bar' foo%%name 'docfb[123]' 'licfb[123]' +touch 'foo b' 'foo a' 'foo r' %install mkdir -p %{buildroot}/opt @@ -38,6 +39,14 @@ touch '%{buildroot}/opt/foo*r' # Macro escaping touch '%{buildroot}/opt/foo%%name' +# Space escaping +touch '%{buildroot}/opt/foo[bax bay]' +touch '%{buildroot}/opt/foo bar' +touch '%{buildroot}/opt/foo" bar"' +touch '%{buildroot}/opt/foo b' +touch '%{buildroot}/opt/foo a' +touch '%{buildroot}/opt/foo r' + # Regression checks touch '%{buildroot}/opt/foo-bar1' touch '%{buildroot}/opt/foo-bar2' @@ -76,6 +85,13 @@ touch '%{buildroot}/opt/foo[123]' %doc foo%%name /opt/foo%%name +# Space escaping +%doc foo\ [bar] +/opt/foo\[bax\ bay\] +/opt/foo\ bar +/opt/foo"\ bar" +/opt/foo\ [bar] + # Regression checks %doc ba* "foo bar" /opt/foo-bar* diff --git a/tests/rpmbuild.at b/tests/rpmbuild.at index 70cb0a5e6..5bede7947 100644 --- a/tests/rpmbuild.at +++ b/tests/rpmbuild.at @@ -476,7 +476,12 @@ runroot rpmbuild -bb --quiet /data/SPECS/globesctest.spec runroot rpm -qpl /build/RPMS/noarch/globesctest-1.0-1.noarch.rpm ], [0], -[/opt/foo"'baz"' +[/opt/foo a +/opt/foo b +/opt/foo bar +/opt/foo r +/opt/foo" bar" +/opt/foo"'baz"' /opt/foo"bar" /opt/foo%name /opt/foo* @@ -489,6 +494,7 @@ runroot rpm -qpl /build/RPMS/noarch/globesctest-1.0-1.noarch.rpm /opt/foo[[123]] /opt/foo[[bar baz]] /opt/foo[[bar]] +/opt/foo[[bax bay]] /opt/foo\ /opt/foo\[[bar\]] /opt/foo\bar @@ -508,7 +514,10 @@ runroot rpm -qpl /build/RPMS/noarch/globesctest-1.0-1.noarch.rpm /opt/share/doc/globesctest-1.0/bar /opt/share/doc/globesctest-1.0/baz /opt/share/doc/globesctest-1.0/docfb[[123]] +/opt/share/doc/globesctest-1.0/foo a +/opt/share/doc/globesctest-1.0/foo b /opt/share/doc/globesctest-1.0/foo bar +/opt/share/doc/globesctest-1.0/foo r /opt/share/doc/globesctest-1.0/foo%name /opt/share/doc/globesctest-1.0/foo[[bar]] /opt/share/licenses/globesctest-1.0 @@ -518,6 +527,21 @@ runroot rpm -qpl /build/RPMS/noarch/globesctest-1.0-1.noarch.rpm ) AT_CLEANUP +AT_SETUP([rpmbuild bad escape]) +AT_KEYWORDS([build]) +AT_CHECK([ +RPMDB_INIT + +runroot rpmbuild -bb --quiet /data/SPECS/badescape.spec +], +[1], +[], +[error: Trailing backslash: /opt/foo\ + +], +) +AT_CLEANUP + AT_SETUP([rpmbuild prefixpostfix]) AT_KEYWORDS([build]) AT_CHECK([ |