Commit 558fe506 by Kaveh R. Ghazi Committed by Kaveh Ghazi

fixfixes.c (char_macro_use_fix, [...]): Don't check the return value of sprintf.

	* fixinc/fixfixes.c (char_macro_use_fix, char_macro_def_fix):
	Don't check the return value of sprintf.  Use asprintf to avoid
	buffer overflows.

From-SVN: r33955
parent 6f6ceed0
2000-05-17 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* fixinc/fixfixes.c (char_macro_use_fix, char_macro_def_fix):
Don't check the return value of sprintf. Use asprintf to avoid
buffer overflows.
Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com> Wed May 17 17:27:44 2000 Andrew Cagney <cagney@b1.cygnus.com>
* flags.h (warn_unused_function, warn_unused_label, * flags.h (warn_unused_function, warn_unused_label,
......
...@@ -296,7 +296,7 @@ FIX_PROC_HEAD( char_macro_use_fix ) ...@@ -296,7 +296,7 @@ FIX_PROC_HEAD( char_macro_use_fix )
#endif #endif
; ;
char zPat[ sizeof( zPatFmt ) + 32 ]; char *pz_pat;
static regex_t re; static regex_t re;
...@@ -309,13 +309,15 @@ FIX_PROC_HEAD( char_macro_use_fix ) ...@@ -309,13 +309,15 @@ FIX_PROC_HEAD( char_macro_use_fix )
exit(3); exit(3);
} }
if (sprintf( zPat, zPatFmt, p_fixd->patch_args[1] ) >= sizeof( zPat )) asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
if (!pz_pat)
{ {
fprintf( stderr, "Oversize format: %s\n", zPat ); fprintf( stderr, "Virtual memory exhausted\n" );
exit(3); exit(3);
} }
compile_re (zPat, &re, 2, "macro pattern", "char_macro_use_fix"); compile_re (pz_pat, &re, 2, "macro pattern", "char_macro_use_fix");
free (pz_pat);
while (regexec (&re, text, 3, rm, 0) == 0) while (regexec (&re, text, 3, rm, 0) == 0)
{ {
...@@ -378,7 +380,7 @@ FIX_PROC_HEAD( char_macro_def_fix ) ...@@ -378,7 +380,7 @@ FIX_PROC_HEAD( char_macro_def_fix )
#endif #endif
; ;
char zPat[ sizeof( zPatFmt ) + 32 ]; char *pz_pat;
static regex_t re; static regex_t re;
...@@ -393,20 +395,23 @@ FIX_PROC_HEAD( char_macro_def_fix ) ...@@ -393,20 +395,23 @@ FIX_PROC_HEAD( char_macro_def_fix )
exit(3); exit(3);
} }
if (sprintf( zPat, zPatFmt, p_fixd->patch_args[1] ) >= sizeof( zPat )) asprintf (&pz_pat, zPatFmt, p_fixd->patch_args[1]);
if (!pz_pat)
{ {
fprintf( stderr, "Oversize format: %s\n", zPat ); fprintf (stderr, "Virtual memory exhausted\n");
exit(3); exit(3);
} }
compile_re (zPat, &re, 1, "macro pattern", "char_macro_def_fix"); compile_re (pz_pat, &re, 1, "macro pattern", "char_macro_def_fix");
if ((rerr = regexec (&re, text, 3, rm, 0)) != 0) if ((rerr = regexec (&re, text, 3, rm, 0)) != 0)
{ {
fprintf( stderr, "Match error %d:\n%s\n", rerr, zPat ); fprintf( stderr, "Match error %d:\n%s\n", rerr, pz_pat );
exit(3); exit(3);
} }
free (pz_pat);
while ((rerr = regexec (&re, text, 3, rm, 0)) == 0) while ((rerr = regexec (&re, text, 3, rm, 0)) == 0)
{ {
const char* pz = text + rm[2].rm_so; const char* pz = text + rm[2].rm_so;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment