[PATCH] kernel: debug: kdb: kdb_io.c: Cleaning up missing null-terminate after strncpy call

From: Rickard Strandqvist
Date: Wed Jun 04 2014 - 17:40:46 EST


Added a guaranteed null-terminate after call to strncpy.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@xxxxxxxxxxxxxxxxxx>
---
kernel/debug/kdb/kdb_io.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 14ff484..0cd0e28 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -441,8 +441,10 @@ poll_again:

char *kdb_getstr(char *buffer, size_t bufsize, char *prompt)
{
- if (prompt && kdb_prompt_str != prompt)
- strncpy(kdb_prompt_str, prompt, CMD_BUFLEN);
+ if (prompt && kdb_prompt_str != prompt) {
+ strncpy(kdb_prompt_str, prompt, sizeof(kdb_prompt_str));
+ kdb_prompt_str[sizeof(kdb_prompt_str) - 1] = '\0'
+ }
kdb_printf(kdb_prompt_str);
kdb_nextline = 1; /* Prompt and input resets line number */
return kdb_read(buffer, bufsize);
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/