summaryrefslogtreecommitdiff
path: root/rpmio/rpmglob.c
diff options
context:
space:
mode:
authorMichal Domonkos <mdomonko@redhat.com>2022-07-27 15:08:33 +0200
committerPanu Matilainen <pmatilai@redhat.com>2022-08-18 12:33:00 +0300
commit1cd7f1ab1e736b0931f19ca701682dc27974af36 (patch)
treef8b4405c5d82de0cb91485df31b7946089222752 /rpmio/rpmglob.c
parentce6247e9e3b5e7719d777488757aa51b8229c187 (diff)
downloadrpm-1cd7f1ab1e736b0931f19ca701682dc27974af36.tar.gz
Don't try to expand URLs in rpmGlob()
By definition, glob(3) matches pathnames on the file system, so no pattern starting with a URL protocol (e.g. http:// or file://) will ever produce any meaningful results when passed to it, it will just fail with GLOB_NOMATCH. This wasn't always the case, we used to call a custom Glob() function here in the past, which knew how to handle URLs, but that was axed in commit 9cbf0349b84fb19c6dddbe4f7a3246d4c949ad09 some 15 years ago. To this day, however, we somewhat continue the legacy by letting URL_IS_PATH (file://) patterns pass through glob(3) if they contain magic chars, with the only possible outcome of failing afterwards. Drop this special case and simply consider any known URL pattern as non-local (int local = 0) and return it immediately. Also remove the no-op URL code while at it.
Diffstat (limited to 'rpmio/rpmglob.c')
-rw-r--r--rpmio/rpmglob.c43
1 files changed, 2 insertions, 41 deletions
diff --git a/rpmio/rpmglob.c b/rpmio/rpmglob.c
index c299cf932..04baa02eb 100644
--- a/rpmio/rpmglob.c
+++ b/rpmio/rpmglob.c
@@ -55,12 +55,9 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
{
int argc = 0;
ARGV_t argv = NULL;
- char * globRoot = NULL;
- char * globURL;
const char *home = getenv("HOME");
const char *path;
- int ut = urlPath(pattern, &path);
- int local = (ut == URL_IS_PATH) || (ut == URL_IS_UNKNOWN);
+ int local = (urlPath(pattern, &path) == URL_IS_UNKNOWN);
size_t plen = strlen(path);
int dir_only = (plen > 0 && path[plen-1] == '/');
glob_t gl;
@@ -70,7 +67,6 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
char * old_ctype = NULL;
const char * t;
#endif
- size_t maxb, nb;
int i;
int rc = 0;
@@ -109,50 +105,15 @@ int rpmGlob(const char * pattern, int * argcPtr, ARGV_t * argvPtr)
if (rc)
goto exit;
- /* XXX Prepend the URL leader for globs that have stripped it off */
- maxb = 0;
for (i = 0; i < gl.gl_pathc; i++) {
- if ((nb = strlen(&(gl.gl_pathv[i][0]))) > maxb)
- maxb = nb;
- }
-
- nb = ((ut == URL_IS_PATH) ? (path - pattern) : 0);
- maxb += nb;
- maxb += 1;
- globURL = globRoot = xmalloc(maxb);
-
- switch (ut) {
- case URL_IS_PATH:
- case URL_IS_DASH:
- strncpy(globRoot, pattern, nb);
- break;
- case URL_IS_HTTPS:
- case URL_IS_HTTP:
- case URL_IS_FTP:
- case URL_IS_HKP:
- case URL_IS_UNKNOWN:
- default:
- break;
- }
- globRoot += nb;
- *globRoot = '\0';
-
- for (i = 0; i < gl.gl_pathc; i++) {
- const char * globFile = &(gl.gl_pathv[i][0]);
-
if (dir_only) {
struct stat sb;
if (lstat(gl.gl_pathv[i], &sb) || !S_ISDIR(sb.st_mode))
continue;
}
-
- if (globRoot > globURL && globRoot[-1] == '/')
- while (*globFile == '/') globFile++;
- strcpy(globRoot, globFile);
- argvAdd(argvPtr, globURL);
+ argvAdd(argvPtr, gl.gl_pathv[i]);
}
globfree(&gl);
- free(globURL);
exit:
argc = argvCount(*argvPtr);