Merge pull request #198 from xfan1024/master

src/libudev/conf-files.c: fix bug of using basename
This commit is contained in:
Boian Bonev 2021-10-07 01:29:07 +03:00 committed by GitHub
commit 3b1286f970
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -71,7 +71,7 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
if (!p)
return -ENOMEM;
r = hashmap_put(h, basename(p), p);
r = hashmap_put(h, eudev_basename(p), p);
if (r == -EEXIST) {
log_debug("Skipping overridden file: %s.", p);
free(p);
@ -92,7 +92,7 @@ static int base_cmp(const void *a, const void *b) {
s1 = *(char * const *)a;
s2 = *(char * const *)b;
return strcmp(basename(s1), basename(s2));
return strcmp(eudev_basename(s1), eudev_basename(s2));
}
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) {

View File

@ -1725,7 +1725,7 @@ int tempfn_xxxxxx(const char *p, char **ret) {
* /foo/bar/.#waldoXXXXXX
*/
fn = basename((char*)p);
fn = eudev_basename(p);
if (!filename_is_valid(fn))
return -EINVAL;
@ -1967,3 +1967,11 @@ void cmsg_close_all(struct msghdr *mh) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
}
const char *eudev_basename(const char *filename) {
const char *p = strrchr(filename, '/');
if (p)
return p + 1;
return filename;
}

View File

@ -433,3 +433,4 @@ union inotify_event_buffer {
};
void cmsg_close_all(struct msghdr *mh);
const char *eudev_basename(const char *filename);