diff options
| author | Shaoxiong Li <dahefanteng@gmail.com> | 2025-06-24 20:19:40 +0800 |
|---|---|---|
| committer | Coly Li <colyli@kernel.org> | 2025-06-24 20:29:55 +0800 |
| commit | 506da7aba97ab8996a451f47a0e69228c8d79889 (patch) | |
| tree | c5d55dec03c99acda78559c4d24f0527632aae6b /bcache.c | |
| parent | a5e3753516bd39c431def86c8dfec8a9cea1ddd4 (diff) | |
| download | bcache-tools-master.tar.gz | |
The strncpy() call in replace_line() was using strlen(src) as the size
parameter instead of the destination buffer size, causing a compiler
warning about potential string truncation. use snprintf() instead.
Signed-off-by: Shaoxiong Li <dahefanteng@gmail.com>
Signed-off-by: Coly Li <colyli@kernel.org>
Diffstat (limited to 'bcache.c')
| -rw-r--r-- | bcache.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -142,7 +142,7 @@ int setlabel_usage(void) return EXIT_FAILURE; } -int version_usagee(void) +int version_usage(void) { fprintf(stderr, "Usage: version display software version\n"); @@ -157,7 +157,7 @@ void replace_line(char **dest, const char *from, const char *to) strcpy(sub, *dest); while (1) { - char *tmp = strpbrk(sub, from); + char *tmp = strstr(sub, from); if (tmp != NULL) { strcpy(new, tmp); @@ -166,7 +166,7 @@ void replace_line(char **dest, const char *from, const char *to) break; } if (strlen(new) > 0) { - strncpy(new, to, strlen(to)); + snprintf(new, sizeof(new), "%s", to); sprintf(*dest + strlen(*dest) - strlen(new), new, strlen(new)); } } @@ -453,7 +453,7 @@ int main(int argc, char **argv) return set_label(devname, argv[2]); } else if (strcmp(subcmd, "version") == 0) { if (argc != 1) - return version_usagee(); + return version_usage(); printf("bcache-tools %s\n", BCACHE_TOOLS_VERSION); return 0; |
