History

safety: replace occurrences of strcpy by pstrcpy

grischka committed 13 years ago

Commit 2f6b8461 parent 370547a4 files · +11 −21Browse files

Unified · Split

4 files
  1. libtcc.c +1 −1
  2. tccelf.c +6 −16
  3. tccgen.c +1 −1
  4. tccpe.c +3 −3
libtcc.c+1−1
@@ -1636,7 +1636,7 @@ PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file) · 1635 unmodified lines
16361636 && *ext)
16371637 strcpy(ext, ".o");
16381638 else
1639− pstrcpy(buf, sizeof(buf), "a.out");
1639+ strcpy(buf, "a.out");
16401640
16411641 return tcc_strdup(buf);
16421642 }
tccelf.c+6−16
@@ -2992,20 +2992,6 @@ static int ld_next(TCCState *s1, char *name, int name_size) · 2991 unmodified lines
29922992 return c;
29932993 }
29942994
2995−/*
2996− * Extract the file name from the library name
2997− *
2998− * /!\ No test on filename capacity, be careful
2999− */
3000−static void libname_to_filename(TCCState *s1, const char libname[], char filename[])
3001−{
3002− if (!s1->static_link) {
3003− sprintf(filename, "lib%s.so", libname);
3004− } else {
3005− sprintf(filename, "lib%s.a", libname);
3006− }
3007−}
3008−
30092995 static int ld_add_file(TCCState *s1, const char filename[])
30102996 {
30112997 int ret;
@@ -3052,8 +3038,12 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 40 unmodified lines
30523038 ret = -1;
30533039 goto lib_parse_error;
30543040 }
3055− strcpy(libname, &filename[1]);
3056− libname_to_filename(s1, libname, filename);
3041+ pstrcpy(libname, sizeof libname, &filename[1]);
3042+ if (s1->static_link) {
3043+ snprintf(filename, sizeof filename, "lib%s.a", libname);
3044+ } else {
3045+ snprintf(filename, sizeof filename, "lib%s.so", libname);
3046+ }
30573047 } else if (t != LD_TOK_NAME) {
30583048 tcc_error_noabort("filename expected");
30593049 ret = -1;
tccgen.c+1−1
@@ -5580,7 +5580,7 @@ ST_FUNC void gen_inline_functions(void) · 5579 unmodified lines
55805580 str = fn->token_str;
55815581 fn->sym = NULL;
55825582 if (file)
5583− strcpy(file->filename, fn->filename);
5583+ pstrcpy(file->filename, sizeof file->filename, fn->filename);
55845584 sym->r = VT_SYM | VT_CONST;
55855585 sym->type.t &= ~VT_INLINE;
55865586
tccpe.c+3−3
@@ -663,7 +663,7 @@ static int pe_write(struct pe_info *pe) · 662 unmodified lines
663663 }
664664 }
665665
666− strcpy((char*)psh->Name, sh_name);
666+ pstrcpy((char*)psh->Name, sizeof psh->Name, sh_name);
667667
668668 psh->Characteristics = pe_sec_flags[si->cls];
669669 psh->VirtualAddress = addr;
@@ -933,7 +933,7 @@ static void pe_build_exports(struct pe_info *pe) · 263 unmodified lines
933933
934934 #if 1
935935 /* automatically write exports to <output-filename>.def */
936− strcpy(buf, pe->filename);
936+ pstrcpy(buf, sizeof buf, pe->filename);
937937 strcpy(tcc_fileextension(buf), ".def");
938938 op = fopen(buf, "w");
939939 if (NULL == op) {
@@ -1598,7 +1598,7 @@ static int pe_load_def(TCCState *s1, FILE *fp) · 658 unmodified lines
15981598 case 0:
15991599 if (0 != strnicmp(p, "LIBRARY", 7))
16001600 goto quit;
1601− strcpy(dllname, trimfront(p+7));
1601+ pstrcpy(dllname, sizeof dllname, trimfront(p+7));
16021602 ++state;
16031603 continue;
16041604

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t