Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
strcpy->strncpy
authordegomme <augustin.degomme@unibas.ch>
Wed, 1 Jun 2016 00:16:20 +0000 (02:16 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Wed, 1 Jun 2016 00:16:20 +0000 (02:16 +0200)
src/xbt/backtrace_linux.c
src/xbt/cunit.c
src/xbt/ex.c
src/xbt/xbt_strbuff.c
tools/sg_unit_extractor.pl

index a1e3fcb..1c83ddb 100644 (file)
@@ -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]);
       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]);
     }
     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) {
     }
 
     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);
           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);
         }
         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);
         }
         pclose(subpipe);
         free(subcmd);
index b669bfa..48393c4 100644 (file)
@@ -462,7 +462,7 @@ static void apply_selection(char *selection)
       dir[p - sel] = '\0';
       sel = p + 1;
     } else {
       dir[p - sel] = '\0';
       sel = p + 1;
     } else {
-      strcpy(dir, sel);
+      strncpy(dir, sel,1024);
       done = 1;
     }
 
       done = 1;
     }
 
@@ -477,11 +477,11 @@ static void apply_selection(char *selection)
 
     p = strchr(dir, ':');
     if (p) {
 
     p = strchr(dir, ':');
     if (p) {
-      strcpy(unitname, p + 1);
+      strncpy(unitname, p + 1,512);
       strncpy(suitename, dir, p - dir);
       suitename[p - dir] = '\0';
     } else {
       strncpy(suitename, dir, p - dir);
       suitename[p - dir] = '\0';
     } else {
-      strcpy(suitename, dir);
+      strncpy(suitename, dir,512);
       unitname[0] = '\0';
     }
 
       unitname[0] = '\0';
     }
 
index 0a4e65e..e641a18 100644 (file)
@@ -393,8 +393,8 @@ static void good_example(void)
       cp1 = NULL /*05 give away */ ;
       cp2 = mallocex(TOOBIG);
       cp3 = mallocex(SMALLAMOUNT);
       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);
     }
     TRY_CLEANUP {               /*04 */
       printf("cp3=%s", cp3 == NULL /*02 */ ? "" : cp3);
index 1d3067c..b73f511 100644 (file)
@@ -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);
   }
     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;
 }
 
   b->used += addlen;
 }
 
index 4c0de32..e626e3d 100755 (executable)
@@ -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') {
       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);
         } else {
           strncat(selection, \",\",1);
-          strncat(selection, p, 1024);
+          strncat(selection, p, 1023);
         }
       } else if (!strcmp(argv[i], \"--verbose\")) {
         verbosity++;
         }
       } else if (!strcmp(argv[i], \"--verbose\")) {
         verbosity++;