summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-31 22:49:30 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-31 22:49:30 +0000
commit3bf3f327b9636a77c99320f0ae74f9f67516edd4 (patch)
treeb7fe9b70ea56a6ca4033c9559ad82f77019d60d4 /usr.bin
parent5fcf4bea9d3d83fd91071bdbe9449083ed0b61de (diff)
recommit strlcpy/snprintf diff after i found my bug
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/lex/gen.c15
-rw-r--r--usr.bin/lex/initscan.c18
-rw-r--r--usr.bin/lex/main.c10
-rw-r--r--usr.bin/lex/misc.c20
-rw-r--r--usr.bin/lex/nfa.c14
-rw-r--r--usr.bin/lex/parse.y15
-rw-r--r--usr.bin/lex/scan.l16
7 files changed, 57 insertions, 51 deletions
diff --git a/usr.bin/lex/gen.c b/usr.bin/lex/gen.c
index b3710592710..6ee7f739ec4 100644
--- a/usr.bin/lex/gen.c
+++ b/usr.bin/lex/gen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gen.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: gen.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
/* gen - actual generation (writing) of flex scanners */
@@ -28,7 +28,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/gen.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/gen.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
@@ -605,17 +605,18 @@ int worry_about_NULs;
if ( worry_about_NULs && ! nultrans )
{
if ( useecs )
- (void) sprintf( char_map,
+ (void) snprintf( char_map, sizeof char_map,
"(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)",
NUL_ec );
else
- (void) sprintf( char_map,
+ (void) snprintf( char_map, sizeof char_map,
"(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec );
}
else
- strcpy( char_map, useecs ?
- "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" );
+ strlcpy( char_map, useecs ?
+ "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)",
+ sizeof char_map );
if ( worry_about_NULs && nultrans )
{
@@ -712,7 +713,7 @@ void gen_NUL_trans()
{
char NUL_ec_str[20];
- (void) sprintf( NUL_ec_str, "%d", NUL_ec );
+ (void) snprintf( NUL_ec_str, sizeof NUL_ec_str, "%d", NUL_ec );
gen_next_compressed_state( NUL_ec_str );
do_indent();
diff --git a/usr.bin/lex/initscan.c b/usr.bin/lex/initscan.c
index 80fe2171fde..6cf3e210306 100644
--- a/usr.bin/lex/initscan.c
+++ b/usr.bin/lex/initscan.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: initscan.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: initscan.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
#line 2 "scan.c"
/* A lexical scanner generated by flex */
/* Scanner skeleton version:
- * $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $
+ * $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $
*/
#define FLEX_SCANNER
@@ -1272,7 +1272,7 @@ char *yytext;
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
#include "parse.h"
@@ -1294,7 +1294,7 @@ char *yytext;
return CHAR;
#define RETURNNAME \
- strcpy( nmstr, yytext ); \
+ strlcpy( nmstr, yytext, sizeof nmstr ); \
return NAME;
#define PUT_BACK_STRING(str, start) \
@@ -1667,7 +1667,7 @@ case 15:
YY_RULE_SETUP
#line 138 "scan.l"
{
- strcpy( nmstr, yytext );
+ strlcpy( nmstr, yytext, sizeof nmstr );
didadef = false;
BEGIN(PICKUPDEF);
}
@@ -1768,7 +1768,7 @@ case 31:
YY_RULE_SETUP
#line 186 "scan.l"
{
- strcpy( (char *) nmdef, yytext );
+ strlcpy( (char *) nmdef, yytext, sizeof nmdef );
/* Skip trailing whitespace. */
for ( i = strlen( (char *) nmdef ) - 1;
@@ -2046,7 +2046,7 @@ case 80:
YY_RULE_SETUP
#line 279 "scan.l"
{
- strcpy( nmstr, yytext + 1 );
+ strlcpy( nmstr, yytext + 1, sizeof nmstr );
nmstr[strlen( nmstr ) - 1] = '\0';
return NAME;
}
@@ -2257,7 +2257,7 @@ YY_RULE_SETUP
{
int cclval;
- strcpy( nmstr, yytext );
+ strlcpy( nmstr, yytext, sizeof nmstr );
/* Check to see if we've already encountered this
* ccl.
@@ -2295,7 +2295,7 @@ YY_RULE_SETUP
Char *nmdefptr;
Char *ndlookup();
- strcpy( nmstr, yytext + 1 );
+ strlcpy( nmstr, yytext + 1, sizeof nmstr );
nmstr[yyleng - 2] = '\0'; /* chop trailing brace */
if ( (nmdefptr = ndlookup( nmstr )) == 0 )
diff --git a/usr.bin/lex/main.c b/usr.bin/lex/main.c
index 438be7e2cea..a3677ea09c6 100644
--- a/usr.bin/lex/main.c
+++ b/usr.bin/lex/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.7 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.8 2002/05/31 22:49:29 deraadt Exp $ */
/* flex - tool to generate fast lexical analyzers */
@@ -34,7 +34,7 @@ char copyright[] =
All rights reserved.\n";
#endif /* not lint */
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/main.c,v 1.7 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/main.c,v 1.8 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
@@ -286,8 +286,8 @@ void check_options()
else
suffix = "c";
- sprintf( outfile_path, outfile_template,
- prefix, suffix );
+ snprintf( outfile_path, sizeof outfile_path,
+ outfile_template, prefix, suffix );
outfilename = outfile_path;
}
@@ -1135,7 +1135,7 @@ _( "%s [-bcdfhilnpstvwBFILTV78+? -C[aefFmr] -ooutput -Pprefix -Sskeleton]\n" ),
if ( ! did_outfilename )
{
- sprintf( outfile_path, outfile_template,
+ snprintf( outfile_path, sizeof outfile_path, outfile_template,
prefix, C_plus_plus ? "cc" : "c" );
outfilename = outfile_path;
}
diff --git a/usr.bin/lex/misc.c b/usr.bin/lex/misc.c
index 146ff823212..2952b4c086d 100644
--- a/usr.bin/lex/misc.c
+++ b/usr.bin/lex/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
/* misc - miscellaneous flex routines */
@@ -28,7 +28,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/misc.c,v 1.8 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/misc.c,v 1.9 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
@@ -46,7 +46,7 @@ int value;
return;
}
- sprintf( buf, "#define %s %d\n", defname, value );
+ snprintf( buf, sizeof buf, "#define %s %d\n", defname, value );
add_action( buf );
}
@@ -364,7 +364,7 @@ const char msg[];
int arg;
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf( errmsg, sizeof errmsg, msg, arg );
flexerror( errmsg );
}
@@ -376,7 +376,7 @@ const char msg[], arg[];
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf( errmsg, sizeof errmsg, msg, arg );
flexerror( errmsg );
}
@@ -414,14 +414,16 @@ int do_infile;
*s2 = '\0';
if ( do_infile )
- sprintf( directive, line_fmt, linenum, filename );
+ snprintf( directive, sizeof directive, line_fmt,
+ linenum, filename );
else
{
if ( output_file == stdout )
/* Account for the line directive itself. */
++out_linenum;
- sprintf( directive, line_fmt, out_linenum, filename );
+ snprintf( directive, sizeof directive, line_fmt,
+ out_linenum, filename );
}
/* If output_file is nil then we should put the directive in
@@ -733,8 +735,8 @@ int c;
#endif
default:
- (void) sprintf( rform, "\\%.3o",
- (unsigned int) c );
+ (void) snprintf( rform, sizeof rform,
+ "\\%.3o", (unsigned int) c );
return rform;
}
}
diff --git a/usr.bin/lex/nfa.c b/usr.bin/lex/nfa.c
index b36fd774236..92db40e8374 100644
--- a/usr.bin/lex/nfa.c
+++ b/usr.bin/lex/nfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfa.c,v 1.7 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: nfa.c,v 1.8 2002/05/31 22:49:29 deraadt Exp $ */
/* nfa - NFA construction routines */
@@ -28,7 +28,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/nfa.c,v 1.7 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/nfa.c,v 1.8 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
@@ -215,7 +215,7 @@ int mach, variable_trail_rule, headcnt, trailcnt;
if ( continued_action )
--rule_linenum[num_rules];
- sprintf( action_text, "case %d:\n", num_rules );
+ snprintf( action_text, sizeof action_text, "case %d:\n", num_rules );
add_action( action_text );
if ( variable_trail_rule )
@@ -247,14 +247,16 @@ int mach, variable_trail_rule, headcnt, trailcnt;
if ( headcnt > 0 )
{
- sprintf( action_text, "%s = %s + %d;\n",
- scanner_cp, scanner_bp, headcnt );
+ snprintf( action_text, sizeof action_text,
+ "%s = %s + %d;\n",
+ scanner_cp, scanner_bp, headcnt );
add_action( action_text );
}
else
{
- sprintf( action_text, "%s -= %d;\n",
+ snprintf( action_text, sizeof action_text,
+ "%s -= %d;\n",
scanner_cp, trailcnt );
add_action( action_text );
}
diff --git a/usr.bin/lex/parse.y b/usr.bin/lex/parse.y
index e8775a085c1..e0edcdf0c85 100644
--- a/usr.bin/lex/parse.y
+++ b/usr.bin/lex/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.6 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.7 2002/05/31 22:49:29 deraadt Exp $ */
/* parse.y - parser for flex input */
@@ -35,7 +35,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/parse.y,v 1.6 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/parse.y,v 1.7 2002/05/31 22:49:29 deraadt Exp $ */
/* Some versions of bison are broken in that they use alloca() but don't
@@ -796,7 +796,8 @@ void build_eof_action()
else
{
sceof[scon_stk[i]] = true;
- sprintf( action_text, "case YY_STATE_EOF(%s):\n",
+ snprintf( action_text, sizeof action_text,
+ "case YY_STATE_EOF(%s):\n",
scname[scon_stk[i]] );
add_action( action_text );
}
@@ -821,7 +822,7 @@ char msg[], arg[];
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf( errmsg, sizeof errmsg, msg, arg );
synerr( errmsg );
}
@@ -843,7 +844,7 @@ char msg[], arg[];
{
char warn_msg[MAXLINE];
- (void) sprintf( warn_msg, msg, arg );
+ (void) snprintf( warn_msg, sizeof warn_msg, msg, arg );
warn( warn_msg );
}
@@ -865,7 +866,7 @@ char msg[], arg[];
{
char errmsg[MAXLINE];
- (void) sprintf( errmsg, msg, arg );
+ (void) snprintf( errmsg, sizeof errmsg, msg, arg );
pinpoint_message( errmsg );
}
@@ -889,7 +890,7 @@ int line;
if ( ! nowarn )
{
- sprintf( warning, "warning, %s", str );
+ snprintf( warning, sizeof warning, "warning, %s", str );
line_pinpoint( warning, line );
}
}
diff --git a/usr.bin/lex/scan.l b/usr.bin/lex/scan.l
index a626301b9e7..dcdad125ccf 100644
--- a/usr.bin/lex/scan.l
+++ b/usr.bin/lex/scan.l
@@ -1,4 +1,4 @@
-/* $OpenBSD: scan.l,v 1.6 2002/05/31 00:56:21 deraadt Exp $ */
+/* $OpenBSD: scan.l,v 1.7 2002/05/31 22:49:29 deraadt Exp $ */
/* scan.l - scanner for flex input */
@@ -29,7 +29,7 @@
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-/* $Header: /cvs/OpenBSD/src/usr.bin/lex/scan.l,v 1.6 2002/05/31 00:56:21 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/scan.l,v 1.7 2002/05/31 22:49:29 deraadt Exp $ */
#include "flexdef.h"
#include "parse.h"
@@ -51,7 +51,7 @@
return CHAR;
#define RETURNNAME \
- strcpy( nmstr, yytext ); \
+ strlcpy( nmstr, yytext, sizeof nmstr); \
return NAME;
#define PUT_BACK_STRING(str, start) \
@@ -138,7 +138,7 @@ LEXOPT [aceknopr]
^"%"[^sxaceknopr{}].* synerr( _( "unrecognized '%' directive" ) );
^{NAME} {
- strcpy( nmstr, yytext );
+ strlcpy( nmstr, yytext, sizeof nmstr );
didadef = false;
BEGIN(PICKUPDEF);
}
@@ -186,7 +186,7 @@ LEXOPT [aceknopr]
{WS} /* separates name and definition */
{NOT_WS}.* {
- strcpy( (char *) nmdef, yytext );
+ strlcpy( (char *) nmdef, yytext, sizeof nmdef);
/* Skip trailing whitespace. */
for ( i = strlen( (char *) nmdef ) - 1;
@@ -279,7 +279,7 @@ LEXOPT [aceknopr]
yyclass return OPT_YYCLASS;
\"[^"\n]*\" {
- strcpy( nmstr, yytext + 1 );
+ strlcpy( nmstr, yytext + 1, sizeof nmstr);
nmstr[strlen( nmstr ) - 1] = '\0';
return NAME;
}
@@ -403,7 +403,7 @@ LEXOPT [aceknopr]
"["({FIRST_CCL_CHAR}|{CCL_EXPR})({CCL_CHAR}|{CCL_EXPR})* {
int cclval;
- strcpy( nmstr, yytext );
+ strlcpy( nmstr, yytext, sizeof nmstr);
/* Check to see if we've already encountered this
* ccl.
@@ -438,7 +438,7 @@ LEXOPT [aceknopr]
register Char *nmdefptr;
Char *ndlookup();
- strcpy( nmstr, yytext + 1 );
+ strlcpy( nmstr, yytext + 1, sizeof nmstr );
nmstr[yyleng - 2] = '\0'; /* chop trailing brace */
if ( (nmdefptr = ndlookup( nmstr )) == 0 )