From 06bbde49d12d7bf16aed3aec54604a9f0f5e97e2 Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Tue, 31 Jan 2012 09:49:29 +0400 Subject: [PATCH] Qsub: fix get_name_value We must pass NULL to smart_strtok if the incoming argument 'start' is NULL. Eventually, fill tmpLine in a more bulletproof way to avoid buffer overflows. Signed-off-by: Eygene Ryabinkin --- src/cmds/qsub.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cmds/qsub.c b/src/cmds/qsub.c index fc8a70b..d6b0e02 100644 --- a/src/cmds/qsub.c +++ b/src/cmds/qsub.c @@ -580,16 +580,23 @@ char **value; char *curr_ptr; char *equals; static char tmpLine[65536]; + char *s; /* we've reached the end */ if ((start == NULL) && (*tok_ptr == '\0')) return(0); + s = NULL; + /* XXX: may truncate input */ if (start != NULL) - strcpy(tmpLine, start); + { + strncpy(tmpLine, start, sizeof(tmpLine)); + tmpLine[sizeof(tmpLine) - 1] = '\0'; + s = tmpLine; + } - curr_ptr = smart_strtok(tmpLine,",",&tok_ptr,FALSE); + curr_ptr = smart_strtok(s,",",&tok_ptr,FALSE); if ((curr_ptr == NULL)) return(0); -- 1.7.8