diff options
author | Alejandro Colomar <alx.manpages@gmail.com> | 2022-06-06 14:18:01 +0200 |
---|---|---|
committer | Alejandro Colomar <alx.manpages@gmail.com> | 2022-06-21 12:47:01 +0200 |
commit | c3e40ae932f0cf9ae33166479049d2d3c9fa1615 (patch) | |
tree | d3fd81d32f648def28d9425d981520e65d189dcc /pkg/rpm | |
parent | d220eb2996513134d3553dbb4ae6b6bbf4692775 (diff) | |
download | unit-c3e40ae932f0cf9ae33166479049d2d3c9fa1615.tar.gz unit-c3e40ae932f0cf9ae33166479049d2d3c9fa1615.tar.bz2 |
Static: Fixed finding the file extension.
The code for finding the extension made a few assumptions that are
no longer true. It didn't account for pathnames that didn't
contain '/', including the empty string, or the NULL string. That
code was used with "share", which always had a '/', but now it's
also used with "index", which should not have a '/' in it.
This fix works by limiting the search to the beginning of the
string, so that if no '/' is found in it, it doesn't continue
searching before the beginning of the string.
This also happens to work for NULL. It is technically Undefined
Behavior, as we rely on `NULL + 0 == NULL` and `NULL - NULL == 0`.
But that is the only sane behavior for an implementation, and all
existing POSIX implementations will Just Work for this code.
Relying on this UB is useful, because we don't need to add an
explicit check for NULL, and therefore we have faster code.
Although the current code can't have a NULL, I expect that when we
add support for variables in the index, it will be NULL in some
cases.
Link: <https://stackoverflow.com/q/67291052/6872717>
The same code seems to be defined behavior in C++, which normally
will share implementation in the compiler for these cases, and
therefore it is really unlikely to be in trouble.
Link: <https://stackoverflow.com/q/59409034/6872717>
Diffstat (limited to 'pkg/rpm')
0 files changed, 0 insertions, 0 deletions