b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | --- a/libkmod/libkmod-config.c |
| 2 | +++ b/libkmod/libkmod-config.c |
| 3 | @@ -21,6 +21,7 @@ |
| 4 | #include <ctype.h> |
| 5 | #include <dirent.h> |
| 6 | #include <errno.h> |
| 7 | +#include <libgen.h> |
| 8 | #include <stdarg.h> |
| 9 | #include <stddef.h> |
| 10 | #include <stdio.h> |
| 11 | @@ -794,7 +795,9 @@ static int conf_files_insert_sorted(stru |
| 12 | bool is_single = false; |
| 13 | |
| 14 | if (name == NULL) { |
| 15 | - name = basename(path); |
| 16 | + char *pathc = strdup(path); |
| 17 | + name = basename(pathc); |
| 18 | + free(pathc); |
| 19 | is_single = true; |
| 20 | } |
| 21 | |
| 22 | --- a/shared/util.c |
| 23 | +++ b/shared/util.c |
| 24 | @@ -22,6 +22,7 @@ |
| 25 | #include <assert.h> |
| 26 | #include <ctype.h> |
| 27 | #include <errno.h> |
| 28 | +#include <libgen.h> |
| 29 | #include <stdarg.h> |
| 30 | #include <stddef.h> |
| 31 | #include <stdio.h> |
| 32 | @@ -173,8 +174,10 @@ char *modname_normalize(const char *modn |
| 33 | char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len) |
| 34 | { |
| 35 | char *modname; |
| 36 | + char *pathc = strdup(path); |
| 37 | |
| 38 | - modname = basename(path); |
| 39 | + modname = basename(pathc); |
| 40 | + free(pathc); |
| 41 | if (modname == NULL || modname[0] == '\0') |
| 42 | return NULL; |
| 43 | |
| 44 | --- a/tools/depmod.c |
| 45 | +++ b/tools/depmod.c |
| 46 | @@ -22,6 +22,7 @@ |
| 47 | #include <dirent.h> |
| 48 | #include <errno.h> |
| 49 | #include <getopt.h> |
| 50 | +#include <libgen.h> |
| 51 | #include <limits.h> |
| 52 | #include <regex.h> |
| 53 | #include <stdio.h> |
| 54 | @@ -757,14 +758,17 @@ static int cfg_files_insert_sorted(struc |
| 55 | struct cfg_file **files, *f; |
| 56 | size_t i, n_files, namelen, dirlen; |
| 57 | void *tmp; |
| 58 | + char *dirc; |
| 59 | |
| 60 | dirlen = strlen(dir); |
| 61 | if (name != NULL) |
| 62 | namelen = strlen(name); |
| 63 | else { |
| 64 | - name = basename(dir); |
| 65 | + dirc = strdup(dir); |
| 66 | + name = basename(dirc); |
| 67 | namelen = strlen(name); |
| 68 | dirlen -= namelen + 1; |
| 69 | + free(dirc); |
| 70 | } |
| 71 | |
| 72 | n_files = *p_n_files; |
| 73 | @@ -2613,7 +2617,7 @@ static int depmod_output(struct depmod * |
| 74 | int mode = 0644; |
| 75 | int fd; |
| 76 | |
| 77 | - snprintf(tmp, sizeof(tmp), "%s.%i.%li.%li", itr->name, getpid(), |
| 78 | + snprintf(tmp, sizeof(tmp), "%s.%i.%" PRId64 ".%" PRId64, itr->name, getpid(), |
| 79 | tv.tv_usec, tv.tv_sec); |
| 80 | fd = openat(dfd, tmp, flags, mode); |
| 81 | if (fd < 0) { |
| 82 | --- a/tools/kmod.c |
| 83 | +++ b/tools/kmod.c |
| 84 | @@ -22,6 +22,7 @@ |
| 85 | #include <stdio.h> |
| 86 | #include <stdlib.h> |
| 87 | #include <string.h> |
| 88 | +#include <libgen.h> |
| 89 | |
| 90 | #include <shared/util.h> |
| 91 | |