kdb: kdb_io: Replace strcpy() by strscpy()
PATCH 1/1 kdb: kdb_io: Replace strcpy() by strscpy()
The strcpy() function is being deprecated. Replace it by the safer strscpy() and fix the following Coverity warning:
"You might overrun the 256-character fixed-size string kdb_buffer by copying cphold without checking the length."
Addresses-Coverity-ID: 138996 ("Copy into fixed size buffer")
--- kernel/debug/kdb/kdb_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/debug/kdb/kdb_io.c +1 -1
@@ -836,7 +836,7 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)*/ if (kdb_grepping_flag && !suspend_grep) { *cphold = replaced_byte; -strcpy (kdb_buffer, cphold); +strscpy (kdb_buffer, cphold,sizeof (kdb_buffer)); len =strlen (kdb_buffer); next_avail = kdb_buffer + len; size_avail =sizeof (kdb_buffer) - len;
Signature · 1 line
2.21.0
Quoted 17 lines · Gustavo A. R. Silva
The
strcpy()function is being deprecated. Replace it by the saferstrscpy()and fix the following Coverity warning:"You might overrun the 256-character fixed-size string
kdb_bufferby copying cphold without checking the length."Addresses-Coverity-ID: 138996 ("Copy into fixed size buffer")
Signed-off-by Gustavo A. R. Silva <[email protected]>--- kernel/debug/kdb/kdb_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/debug/kdb/kdb_io.c +0
-0
kernel/debug/kdb/kdb_io.c int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) · line 839
Quoted 5 lines
kernel/debug/kdb/kdb_io.c +1
-1@@ -836,7 +836,7 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap)*/ if (kdb_grepping_flag && !suspend_grep) { *cphold = replaced_byte; -strcpy (kdb_buffer, cphold); +strscpy (kdb_buffer, cphold,sizeof (kdb_buffer));
This looks like a mechanical or semi-mechanical fix... I think it misses a couple of things.
Firstly this code pattern appears twice in the file but you have only fixed on of those instances. If this fix is required then both should be changed.
Secondly cphold is a pointer into kdb_buffer itself which means that *neither* strcpy() nor strscpy() are safe (since their behaviour is undefined) so we should probably be using memmove() anyway.
Daniel.
PS there is an range change since a sub-string is always shorted than a
string (albeit an implicit one based on correct termination handling) so a strlen()+memmove() fix is probably OK here.
Daniel.
Quoted 6 lines
kernel/debug/kdb/kdb_io.c +0
-0len =strlen (kdb_buffer); next_avail = kdb_buffer + len; size_avail =sizeof (kdb_buffer) - len;Signature · 1 line
2.21.0