From e0f5b1396e515206ffc770ebd09a542256443c82 Mon Sep 17 00:00:00 2001 From: degomme Date: Wed, 1 Jun 2016 02:16:20 +0200 Subject: [PATCH] strcpy->strncpy --- src/xbt/backtrace_linux.c | 8 ++++---- src/xbt/cunit.c | 6 +++--- src/xbt/ex.c | 4 ++-- src/xbt/xbt_strbuff.c | 2 +- tools/sg_unit_extractor.pl | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/xbt/backtrace_linux.c b/src/xbt/backtrace_linux.c index a1e3fcbf2a..1c83ddb1cb 100644 --- a/src/xbt/backtrace_linux.c +++ b/src/xbt/backtrace_linux.c @@ -210,13 +210,13 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) //FIXME: This code could be greatly im line_func[strlen(line_func) - 1] = '\0'; } else { XBT_VERB("Cannot run fgets to look for symbol %d, addr %s", i, addrs[i]); - strcpy(line_func, "???"); + strncpy(line_func, "???",3); } if (fgets(line_pos, 1024, pipe)) { line_pos[strlen(line_pos) - 1] = '\0'; } else { XBT_VERB("Cannot run fgets to look for symbol %d, addr %s", i, addrs[i]); - strcpy(line_pos, backtrace_syms[i]); + strncpy(line_pos, backtrace_syms[i],1024); } if (strcmp("??", line_func) != 0) { @@ -311,13 +311,13 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) //FIXME: This code could be greatly im line_func[strlen(line_func) - 1] = '\0'; } else { XBT_VERB("Cannot read result of subcommand %s", subcmd); - strcpy(line_func, "???"); + strncpy(line_func, "???",3); } if (fgets(line_pos, 1024, subpipe)) { line_pos[strlen(line_pos) - 1] = '\0'; } else { XBT_VERB("Cannot read result of subcommand %s", subcmd); - strcpy(line_pos, backtrace_syms[i]); + strncpy(line_pos, backtrace_syms[i],1024); } pclose(subpipe); free(subcmd); diff --git a/src/xbt/cunit.c b/src/xbt/cunit.c index b669bfa632..48393c4dce 100644 --- a/src/xbt/cunit.c +++ b/src/xbt/cunit.c @@ -462,7 +462,7 @@ static void apply_selection(char *selection) dir[p - sel] = '\0'; sel = p + 1; } else { - strcpy(dir, sel); + strncpy(dir, sel,1024); done = 1; } @@ -477,11 +477,11 @@ static void apply_selection(char *selection) p = strchr(dir, ':'); if (p) { - strcpy(unitname, p + 1); + strncpy(unitname, p + 1,512); strncpy(suitename, dir, p - dir); suitename[p - dir] = '\0'; } else { - strcpy(suitename, dir); + strncpy(suitename, dir,512); unitname[0] = '\0'; } diff --git a/src/xbt/ex.c b/src/xbt/ex.c index 0a4e65ec40..e641a18469 100644 --- a/src/xbt/ex.c +++ b/src/xbt/ex.c @@ -393,8 +393,8 @@ static void good_example(void) cp1 = NULL /*05 give away */ ; cp2 = mallocex(TOOBIG); cp3 = mallocex(SMALLAMOUNT); - strcpy(cp1, "foo"); - strcpy(cp2, "bar"); + strncpy(cp1, "foo",3); + strncpy(cp2, "bar",3); } TRY_CLEANUP { /*04 */ printf("cp3=%s", cp3 == NULL /*02 */ ? "" : cp3); diff --git a/src/xbt/xbt_strbuff.c b/src/xbt/xbt_strbuff.c index 1d3067c542..b73f511f62 100644 --- a/src/xbt/xbt_strbuff.c +++ b/src/xbt/xbt_strbuff.c @@ -68,7 +68,7 @@ void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd) b->size = MAX(minimal_increment + b->used, needed_space); b->data = xbt_realloc(b->data, b->size); } - strcpy(b->data + b->used, toadd); + strncpy(b->data + b->used, toadd, b->size-b->used); b->used += addlen; } diff --git a/tools/sg_unit_extractor.pl b/tools/sg_unit_extractor.pl index 4c0de32889..e626e3d096 100755 --- a/tools/sg_unit_extractor.pl +++ b/tools/sg_unit_extractor.pl @@ -149,10 +149,10 @@ int main(int argc, char *argv[]) { if (!strncmp(argv[i],\"--tests=\",strlen(\"--tests=\"))) { char *p=strchr(argv[i],'=')+1; if (selection[0] == '\\0') { - strcpy(selection, p); + strncpy(selection,p,1024); } else { strncat(selection, \",\",1); - strncat(selection, p, 1024); + strncat(selection, p, 1023); } } else if (!strcmp(argv[i], \"--verbose\")) { verbosity++; -- 2.20.1