diff options
author | Prarit Bhargava <prarit@redhat.com> | 2018-09-20 08:59:14 -0400 |
---|---|---|
committer | Daniel Thompson <daniel.thompson@linaro.org> | 2018-11-13 15:27:53 -0500 |
commit | c2b94c72d93d0929f48157eef128c4f9d2e603ce (patch) | |
tree | a38909e62dae0ea7c75f7bcc63f375bacd594f96 /kernel | |
parent | 568fb6f42ac6851320adaea25f8f1b94de14e40a (diff) |
kdb: Use strscpy with destination buffer size
gcc 8.1.0 warns with:
kernel/debug/kdb/kdb_support.c: In function ‘kallsyms_symbol_next’:
kernel/debug/kdb/kdb_support.c:239:4: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
strncpy(prefix_name, name, strlen(name)+1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kernel/debug/kdb/kdb_support.c:239:31: note: length computed here
Use strscpy() with the destination buffer size, and use ellipses when
displaying truncated symbols.
v2: Use strscpy()
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
Cc: Jonathan Toppins <jtoppins@redhat.com>
Cc: Jason Wessel <jason.wessel@windriver.com>
Cc: Daniel Thompson <daniel.thompson@linaro.org>
Cc: kgdb-bugreport@lists.sourceforge.net
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/debug/kdb/kdb_io.c | 15 | ||||
-rw-r--r-- | kernel/debug/kdb/kdb_private.h | 2 | ||||
-rw-r--r-- | kernel/debug/kdb/kdb_support.c | 10 |
3 files changed, 15 insertions, 12 deletions
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index ed5d34925ad0..6a4b41484afe 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c | |||
@@ -216,7 +216,7 @@ static char *kdb_read(char *buffer, size_t bufsize) | |||
216 | int count; | 216 | int count; |
217 | int i; | 217 | int i; |
218 | int diag, dtab_count; | 218 | int diag, dtab_count; |
219 | int key; | 219 | int key, buf_size, ret; |
220 | 220 | ||
221 | 221 | ||
222 | diag = kdbgetintenv("DTABCOUNT", &dtab_count); | 222 | diag = kdbgetintenv("DTABCOUNT", &dtab_count); |
@@ -336,9 +336,8 @@ poll_again: | |||
336 | else | 336 | else |
337 | p_tmp = tmpbuffer; | 337 | p_tmp = tmpbuffer; |
338 | len = strlen(p_tmp); | 338 | len = strlen(p_tmp); |
339 | count = kallsyms_symbol_complete(p_tmp, | 339 | buf_size = sizeof(tmpbuffer) - (p_tmp - tmpbuffer); |
340 | sizeof(tmpbuffer) - | 340 | count = kallsyms_symbol_complete(p_tmp, buf_size); |
341 | (p_tmp - tmpbuffer)); | ||
342 | if (tab == 2 && count > 0) { | 341 | if (tab == 2 && count > 0) { |
343 | kdb_printf("\n%d symbols are found.", count); | 342 | kdb_printf("\n%d symbols are found.", count); |
344 | if (count > dtab_count) { | 343 | if (count > dtab_count) { |
@@ -350,9 +349,13 @@ poll_again: | |||
350 | } | 349 | } |
351 | kdb_printf("\n"); | 350 | kdb_printf("\n"); |
352 | for (i = 0; i < count; i++) { | 351 | for (i = 0; i < count; i++) { |
353 | if (WARN_ON(!kallsyms_symbol_next(p_tmp, i))) | 352 | ret = kallsyms_symbol_next(p_tmp, i, buf_size); |
353 | if (WARN_ON(!ret)) | ||
354 | break; | 354 | break; |
355 | kdb_printf("%s ", p_tmp); | 355 | if (ret != -E2BIG) |
356 | kdb_printf("%s ", p_tmp); | ||
357 | else | ||
358 | kdb_printf("%s... ", p_tmp); | ||
356 | *(p_tmp + len) = '\0'; | 359 | *(p_tmp + len) = '\0'; |
357 | } | 360 | } |
358 | if (i >= dtab_count) | 361 | if (i >= dtab_count) |
diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h index 1e5a502ba4a7..2118d8258b7c 100644 --- a/kernel/debug/kdb/kdb_private.h +++ b/kernel/debug/kdb/kdb_private.h | |||
@@ -83,7 +83,7 @@ typedef struct __ksymtab { | |||
83 | unsigned long sym_start; | 83 | unsigned long sym_start; |
84 | unsigned long sym_end; | 84 | unsigned long sym_end; |
85 | } kdb_symtab_t; | 85 | } kdb_symtab_t; |
86 | extern int kallsyms_symbol_next(char *prefix_name, int flag); | 86 | extern int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size); |
87 | extern int kallsyms_symbol_complete(char *prefix_name, int max_len); | 87 | extern int kallsyms_symbol_complete(char *prefix_name, int max_len); |
88 | 88 | ||
89 | /* Exported Symbols for kernel loadable modules to use. */ | 89 | /* Exported Symbols for kernel loadable modules to use. */ |
diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c index 987eb73284d2..b14b0925c184 100644 --- a/kernel/debug/kdb/kdb_support.c +++ b/kernel/debug/kdb/kdb_support.c | |||
@@ -221,11 +221,13 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len) | |||
221 | * Parameters: | 221 | * Parameters: |
222 | * prefix_name prefix of a symbol name to lookup | 222 | * prefix_name prefix of a symbol name to lookup |
223 | * flag 0 means search from the head, 1 means continue search. | 223 | * flag 0 means search from the head, 1 means continue search. |
224 | * buf_size maximum length that can be written to prefix_name | ||
225 | * buffer | ||
224 | * Returns: | 226 | * Returns: |
225 | * 1 if a symbol matches the given prefix. | 227 | * 1 if a symbol matches the given prefix. |
226 | * 0 if no string found | 228 | * 0 if no string found |
227 | */ | 229 | */ |
228 | int kallsyms_symbol_next(char *prefix_name, int flag) | 230 | int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size) |
229 | { | 231 | { |
230 | int prefix_len = strlen(prefix_name); | 232 | int prefix_len = strlen(prefix_name); |
231 | static loff_t pos; | 233 | static loff_t pos; |
@@ -235,10 +237,8 @@ int kallsyms_symbol_next(char *prefix_name, int flag) | |||
235 | pos = 0; | 237 | pos = 0; |
236 | 238 | ||
237 | while ((name = kdb_walk_kallsyms(&pos))) { | 239 | while ((name = kdb_walk_kallsyms(&pos))) { |
238 | if (strncmp(name, prefix_name, prefix_len) == 0) { | 240 | if (!strncmp(name, prefix_name, prefix_len)) |
239 | strncpy(prefix_name, name, strlen(name)+1); | 241 | return strscpy(prefix_name, name, buf_size); |
240 | return 1; | ||
241 | } | ||
242 | } | 242 | } |
243 | return 0; | 243 | return 0; |
244 | } | 244 | } |