Messages in this thread Patch in this message | | | From | Rickard Strandqvist <> | Subject | [PATCH] kernel: debug: kdb: kdb_main.c: Cleaning up missing null-terminate in conjunction with strncpy | Date | Sat, 26 Jul 2014 16:46:29 +0200 |
| |
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se> --- kernel/debug/kdb/kdb_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 2f7c760..b750c20 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -1063,12 +1063,12 @@ static int handle_ctrl_cmd(char *cmd) case CTRL_P: if (cmdptr != cmd_tail) cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT; - strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); + strlcpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); return 1; case CTRL_N: if (cmdptr != cmd_head) cmdptr = (cmdptr+1) % KDB_CMD_HISTORY_COUNT; - strncpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); + strlcpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); return 1; } return 0; @@ -1263,17 +1263,15 @@ do_full_getstr: if (*cmdbuf != '\n') { if (*cmdbuf < 32) { if (cmdptr == cmd_head) { - strncpy(cmd_hist[cmd_head], cmd_cur, + strlcpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); - *(cmd_hist[cmd_head] + - strlen(cmd_hist[cmd_head])-1) = '\0'; } if (!handle_ctrl_cmd(cmdbuf)) *(cmd_cur+strlen(cmd_cur)-1) = '\0'; cmdbuf = cmd_cur; goto do_full_getstr; } else { - strncpy(cmd_hist[cmd_head], cmd_cur, + strlcpy(cmd_hist[cmd_head], cmd_cur, CMD_BUFLEN); } -- 1.7.10.4
| |