safety: replace occurrences of strcpy by pstrcpy
authorgrischka <grischka>
Thu, 31 Jan 2013 10:29:45 +0000 (31 11:29 +0100)
committergrischka <grischka>
Thu, 31 Jan 2013 12:23:19 +0000 (31 13:23 +0100)
libtcc.c
tccelf.c
tccgen.c
tccpe.c

index b0a9b1a..68b3e10 100644 (file)
--- a/libtcc.c
+++ b/libtcc.c
@@ -1636,7 +1636,7 @@ PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file)
         && *ext)
         strcpy(ext, ".o");
     else
-        pstrcpy(buf, sizeof(buf), "a.out");
+        strcpy(buf, "a.out");
 
     return tcc_strdup(buf);
 }
index 5582bc5..152c4fb 100644 (file)
--- a/tccelf.c
+++ b/tccelf.c
@@ -2992,20 +2992,6 @@ static int ld_next(TCCState *s1, char *name, int name_size)
     return c;
 }
 
-/*
- * Extract the file name from the library name
- *
- * /!\ No test on filename capacity, be careful
- */
-static void libname_to_filename(TCCState *s1, const char libname[], char filename[])
-{
-    if (!s1->static_link) {
-        sprintf(filename, "lib%s.so", libname);
-    } else {
-        sprintf(filename, "lib%s.a", libname);
-    }
-}
-
 static int ld_add_file(TCCState *s1, const char filename[])
 {
     int ret;
@@ -3052,8 +3038,12 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
                 ret = -1;
                 goto lib_parse_error;
             }
-            strcpy(libname, &filename[1]);
-            libname_to_filename(s1, libname, filename);
+            pstrcpy(libname, sizeof libname, &filename[1]);
+            if (s1->static_link) {
+                snprintf(filename, sizeof filename, "lib%s.a", libname);
+            } else {
+                snprintf(filename, sizeof filename, "lib%s.so", libname);
+            }
         } else if (t != LD_TOK_NAME) {
             tcc_error_noabort("filename expected");
             ret = -1;
index 51ac0b1..69941f9 100644 (file)
--- a/tccgen.c
+++ b/tccgen.c
@@ -5580,7 +5580,7 @@ ST_FUNC void gen_inline_functions(void)
                 str = fn->token_str;
                 fn->sym = NULL;
                 if (file)
-                    strcpy(file->filename, fn->filename);
+                    pstrcpy(file->filename, sizeof file->filename, fn->filename);
                 sym->r = VT_SYM | VT_CONST;
                 sym->type.t &= ~VT_INLINE;
 
diff --git a/tccpe.c b/tccpe.c
index 9bee9c2..b55bd93 100644 (file)
--- a/tccpe.c
+++ b/tccpe.c
@@ -663,7 +663,7 @@ static int pe_write(struct pe_info *pe)
             }
         }
 
-        strcpy((char*)psh->Name, sh_name);
+        pstrcpy((char*)psh->Name, sizeof psh->Name, sh_name);
 
         psh->Characteristics = pe_sec_flags[si->cls];
         psh->VirtualAddress = addr;
@@ -933,7 +933,7 @@ static void pe_build_exports(struct pe_info *pe)
 
 #if 1
     /* automatically write exports to <output-filename>.def */
-    strcpy(buf, pe->filename);
+    pstrcpy(buf, sizeof buf, pe->filename);
     strcpy(tcc_fileextension(buf), ".def");
     op = fopen(buf, "w");
     if (NULL == op) {
@@ -1598,7 +1598,7 @@ static int pe_load_def(TCCState *s1, FILE *fp)
         case 0:
             if (0 != strnicmp(p, "LIBRARY", 7))
                 goto quit;
-            strcpy(dllname, trimfront(p+7));
+            pstrcpy(dllname, sizeof dllname, trimfront(p+7));
             ++state;
             continue;