summaryrefslogtreecommitdiff
path: root/rpmio/rpmglob.c
Commit message (Collapse)AuthorAgeFilesLines
* Try globs literally when there are no matchesMichal Domonkos2022-09-201-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | When a glob yields no matches, try accessing a file named like the literal pattern before finally giving up. Do this for any globs supplied by the user, be it on the CLI or through a %files section. We already do this with regular files in %files, this commit just extends the same logic to the remaining places, namely special files (%doc or %license) and package files passed on the CLI in install or query mode (either directly or indirectly through a manifest). This makes globbing in RPM consistent and more shell-like as Bash does the same by default. Do this by treating globs as filenames that may or may not expand into multiple ones. That way, both cases can be handled by the same code path. We don't need to check for the existence of the literal pattern since that's eventually taken care of in the rpmGlob() caller, such as in addFile(). As a nice side effect, error reporting for missing glob and non-glob filenames is now also unified, see the updated tests. Preserve the public signature of rpmGlob(), though, by adding a new, more general wrapper that also takes flags. The name is chosen to fit the pre-existing scheme of rpm*Path() functions in rpmfileutil.h.
* Refactor rpmGlob()Michal Domonkos2022-08-181-13/+12
| | | | | No functional change, just shuffle some lines around for better readability.
* Return GLOB_NOMATCH on missing dirs from rpmGlob()Michal Domonkos2022-08-181-1/+1
| | | | | | | | | | | | As per GNU glob(3), GLOB_ONLYDIR does not guarantee the matches are in fact directories, that's why we check them with lstat(2). That may lead to the match list being empty even after a successful glob() run (rc == 0), so for consistency, return GLOB_NOMATCH in that case, just like we would for a missing file. No functional change since we don't check for the exact return code in the callers, only whether it's positive or not.
* Return arg count 0 from rpmGlob()Michal Domonkos2022-08-181-5/+3
| | | | | | Do set *argcPtr even if the actual count is 0, rather than leaving it unchanged and thus possibly undefined in the caller. This is also consistent with how glob(3) works.
* Don't try to expand URLs in rpmGlob()Michal Domonkos2022-08-181-41/+2
| | | | | | | | | | | | | | | | | | 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.
* Append to arglist in rpmGlob()Michal Domonkos2022-08-181-8/+8
| | | | | | | | | | | | Instead of constructing a new list from scratch and returning that, just extend the passed list. This makes it easier to use this function incrementally when expanding multiple patterns in a loop, such as during package manifest parsing which we adapt here right away. Preserve the ability to pass NULL as argvPtr and still get a match count via argcPtr, by keeping the local argv around for that case. No functional change.
* Fix non-glob fallthrough in rpmGlob()Michal Domonkos2022-08-171-17/+15
| | | | | | | | | | | | | | | | | Now that we directly use GLOB_NOMAGIC to implement a fallthrough for non-glob patterns since commit 9e541c6a7da076bc1c1beb1ee45fd5fdd735358c, we may ironically end up subjecting such patterns to the lstat(2) check at the end if they're directories, and thus possibly not return them. While the actual impact on our codebase seems to be minimal, mostly in terms of pushing the point of failure elsewhere and possibly printing a different error message, for the sake of consistency with the idea of GLOB_NOMAGIC, fix this by bringing back the short-circuit check. While at it, make it a bit simpler than the original rpmIsGlob() by leaving out the well-formedness check (i.e. if a bracket/brace has a closing counterpart) as that's not what GLOB_NOMAGIC does either. Remove the now unused next_brace_sub() as part of that.
* Add shell-like escape support to %filesMichal Domonkos2022-06-271-63/+0
| | | | | | | | | | | | | | | | | | | | | | Make sure any quoted metacharacters in a pattern are unescaped before it's passed to addFile() and subsequently lstat(2). Do this by always letting such patterns through rpmGlob() which now handles backslashes properly since commit 4030062f2bf16d7a4540c78c1e61706f3810fe9b. Don't expand globs twice in processSpecialDir(), though. Axe the public rpmIsGlob() which is no longer needed, we'll be bumping the soname in 4.19. Construct absolute file names directly without going through rpmGenPath() so that literal (double) percent signs are not expanded twice and can be used the same way as in other parts of a spec file. This means URLs are not handled anymore but we're dealing with local files here so that should be fine. Add the "cp" binary to the test environment, it's needed for the %doc directives which copy stuff around. Fixes: #1749
* Refactor rpmGlob()Michal Domonkos2022-06-271-71/+67
| | | | | | | | | Unindent the block touched in the previous commit and move declarations to the beginning, dropping the now redundant gflags in the process. Best served with "git show --ignore-all-space". No functional change.
* Fix rpmGlob() escape supportMichal Domonkos2022-06-271-24/+14
| | | | | | | | | | | | | | | | | | | | | | | | We currently accept a space-separated list of patterns here so any backslash, whether it belongs to a space char or not, gets consumed by poptParseArgvString() before the string is passed to glob(3), requiring callers to double-escape anything they wish to keep literal. Fix that by only accepting one pattern. Adapt the one caller which relies on this actually being a list, in rpmReadPackageManifest(), and those callers where we preserve spaces by escaping them which is no longer needed. Replace our own heuristic emulating GLOB_NOMAGIC with the actual flag to glob(3) so that literal (double) backslashes are also handled properly. Keep the indentation of the original for loop to make the diff easier to read, next commit will fix that. No immediate effect within RPM since we currently avoid passing escaped patterns to rpmGlob(), this is just a prerequisite for the following commits. External users of rpmGlob(), as unlikely as they are, might, in theory, notice this subtle change but we'll be bumping the soname in 4.19 so that's covered.
* Axe our internal and buggy glob() and fnmatch() copiesPanu Matilainen2022-05-041-717/+2
| | | | | | | | | | | | | | | | | glibc 2.2 (or thereabouts) changed glob() and fnmatch() to not return dangling symlinks as matches, which gravely affects rpmbuild in particular. Because of this, rpm has carried a bundled copies of glibc 2.1 functions for close to 22 years now (commit bed2a465fe49ce05f9678e619d016a2d26649c98). glibc 2.27 in 2018 thankfully finally reverted that particular braindamage, I think we've carried the compatibility babbage long enough to excuse ourselves with a little shorter grace period in this case. Nukes away, add a blurb about the version requirement on glibc based systems. This still leaves our internal glob_pattern_p() intact as unlike glob() itself, that's not portable. No functional changes as such.
* Flush 1998 vintage dirent.h compatibility mess from system.hPanu Matilainen2020-04-021-3/+2
| | | | | | | | dirent.h and struct dirent are actually standard on this millenium, the only thing that isn't is d_type member for which we have and retain a specific test in configure.ac. Include <dirent.h> where needed, relatively few places do which makes it even a bigger insult to have this included from system.h.
* Fix buffer overrun in glob tilde expansionPanu Matilainen2018-10-101-1/+1
| | | | | Similar to 8dda888e14df323e1dc1e76a42851e68980658cd but this one noticed by covscan: not enough space for the terminating \0.
* Inode zero is just a regular inodePanu Matilainen2017-09-091-10/+0
| | | | | Inspired by a similar change in glibc: https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=686f2ea18374a541d203cfcc0e1dfba1666f49c2
* Cosmetics: if, while and switch are followed by a spacePanu Matilainen2017-02-271-1/+1
| | | | | | | | The missing space style-error has been recently coming common enough somebody might think that IS the expected style, its not. Some of these are actually very old, but fix across the board for consistency.. Strictly white-space only change.
* Fix off-by-one stack write in rpmGlob() (RhBug:1371914)Panu Matilainen2016-11-161-1/+1
| | | | | | Happens with eg pattern "~0//0", easily visible if alloca() is changed to malloc(). Reported as a security concern, dunno about that but a bug it is anyway.
* Fix next_brace_sub() to return NULL if braces don't match.Lubos Kardos2015-11-181-21/+6
| | | | | | | | | Our implementation of glob() is copied from glibc (2.1 probably) which has buggy implementation of next_brace_sub(). It is fixed in the newer version of glibc. Now next_brace_sub() is modified according to newer (fixed) version of glic. We didn't reveal this bug sooner because brace expansion was disabled in rpm but we enabled brace expansion in commit d14ecfe587efbe80e5534161dbd3a4f7158b4e2b.
* Modify rpmIsGlob() to be more precise.Lubos Kardos2015-08-031-25/+32
| | | | | | | Now rpmIsGlob() checks if braces expansion pattern is well formed and not only if it contains opening and closing brace. The checking procedure is same as procedure in glob() so rpmIsGlob() and glob() are now compatible.
* Enable {} expansion in rpmGlob() (rhbz:1246743)Lubos Kardos2015-07-271-10/+32
|
* Only use local mempcpy() if system libraries dont provide onePanu Matilainen2012-05-311-0/+2
| | | | | - Obvious yes, but how come this didn't barf on my other rather identical system? Meh.
* xmalloc() and xrealloc() never fail, remove redundant checksPanu Matilainen2012-05-311-46/+1
|
* Call alloca() and stat() by their own names...Panu Matilainen2012-05-311-14/+12
|
* Eliminate unnecessary glob portability fiddlesPanu Matilainen2012-05-311-14/+0
| | | | | - Flags available to our internal glob implementation do not depend on posix/gnu/bsd defines
* Eliminate VMS, MS-DOS, Windows and Amiga compatibility hacks in rpmglobPanu Matilainen2012-05-311-77/+4
| | | | - We'll never run on these platforms, we just dont care...
* Eliminate shell interruptability hack in rpmglobPanu Matilainen2012-05-311-16/+1
|
* We always have xstrdup() available, eliminate redundant alternatvePanu Matilainen2012-05-311-10/+0
|
* Eliminate getpwnam_r() and getlogin_r() uses from rpmglobPanu Matilainen2012-05-311-60/+0
| | | | | - We dont particularly care if rpmGlob() is thread-safe or not, just use the simpler code-path
* Eliminate mempcpy() related conditionals from rpmglobPanu Matilainen2012-05-311-65/+4
| | | | | - Provide a local copy of the trivial mempcpy() function so we can always use the shorter code-path, eliminate now unnecessary ifdef goo.
* Remove __GNUC__ conditionals on variable sized local arraysPanu Matilainen2012-05-311-22/+0
| | | | - We require a C99 compiler anyway so these conditionals are not needed
* Eliminate unnecessary libc header typedeffery from rpmglobPanu Matilainen2012-05-311-86/+25
| | | | | - No doubt important bits in glibc but unnecessary goo for our internal implementation.
* Run indent -kr on the glob implementationPanu Matilainen2012-05-311-942/+847
| | | | | - rpm style isn't exactly K&R but close enuf for goverment work and prevent sore eyes now that this is a "real" part of rpm.
* Bury our glob() implementation entirely inside rpmglob.c (RhBug:819680)Panu Matilainen2012-05-311-1/+1275
| | | | | | - Lump glob.h and glob.c into rpmglob.c in all their g(l)ory libc decorations and make everything static to stop overriding system library symbols with our own glob().
* Export our own version of glob_pattern_p() as rpmIsGlob()Panu Matilainen2012-05-311-1/+5
| | | | - Further preliminaries to hiding the glob() implementation
* Split rpmGlob() to a separate source filePanu Matilainen2012-05-311-0/+148
- As a preliminary step to hiding our internal glob implementation, split our only glob() user to a source of its own.