summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-30 10:53:46 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-30 10:53:46 +0000
commit27fd3e6a6743421739e5ab920b0d40cb00062180 (patch)
tree1ef7f2807a52f25fac6044b94c573a102d9ec065
parent3b3586c30c70241fc6f182df78a91d7ebed6ddac (diff)
use strlcpy and snprintf
-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.l17
7 files changed, 57 insertions, 52 deletions
diff --git a/usr.bin/lex/gen.c b/usr.bin/lex/gen.c
index 7db6c2c978c..0acd0718db5 100644
--- a/usr.bin/lex/gen.c
+++ b/usr.bin/lex/gen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gen.c,v 1.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $OpenBSD: gen.c,v 1.7 2002/05/30 10:53:44 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.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/gen.c,v 1.7 2002/05/30 10:53:44 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 9d33e2a50df..47a25c0d6b4 100644
--- a/usr.bin/lex/initscan.c
+++ b/usr.bin/lex/initscan.c
@@ -1,10 +1,10 @@
-/* $OpenBSD: initscan.c,v 1.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $OpenBSD: initscan.c,v 1.7 2002/05/30 10:53:44 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.6 2001/11/19 19:02:14 mpech Exp $
+ * $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.7 2002/05/30 10:53:44 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.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/initscan.c,v 1.7 2002/05/30 10:53:44 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 e4378a99f31..d174b03b947 100644
--- a/usr.bin/lex/main.c
+++ b/usr.bin/lex/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.5 2001/06/17 07:30:42 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.6 2002/05/30 10:53:44 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.5 2001/06/17 07:30:42 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/main.c,v 1.6 2002/05/30 10:53:44 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 4ed619cf92e..51667103ae2 100644
--- a/usr.bin/lex/misc.c
+++ b/usr.bin/lex/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $OpenBSD: misc.c,v 1.7 2002/05/30 10:53:44 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.6 2001/11/19 19:02:14 mpech Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/misc.c,v 1.7 2002/05/30 10:53:44 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 3842e2f11f6..c92256da3ad 100644
--- a/usr.bin/lex/nfa.c
+++ b/usr.bin/lex/nfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nfa.c,v 1.5 2001/11/19 19:02:14 mpech Exp $ */
+/* $OpenBSD: nfa.c,v 1.6 2002/05/30 10:53:44 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.5 2001/11/19 19:02:14 mpech Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/nfa.c,v 1.6 2002/05/30 10:53:44 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 7b2f872efd3..ffebdf06c19 100644
--- a/usr.bin/lex/parse.y
+++ b/usr.bin/lex/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.4 2001/06/17 07:30:42 deraadt Exp $ */
+/* $OpenBSD: parse.y,v 1.5 2002/05/30 10:53:45 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.4 2001/06/17 07:30:42 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/parse.y,v 1.5 2002/05/30 10:53:45 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 2b14b11a85f..e692e2f0204 100644
--- a/usr.bin/lex/scan.l
+++ b/usr.bin/lex/scan.l
@@ -1,4 +1,4 @@
-/* $OpenBSD: scan.l,v 1.4 2001/06/17 07:30:42 deraadt Exp $ */
+/* $OpenBSD: scan.l,v 1.5 2002/05/30 10:53:45 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.4 2001/06/17 07:30:42 deraadt Exp $ */
+/* $Header: /cvs/OpenBSD/src/usr.bin/lex/scan.l,v 1.5 2002/05/30 10:53:45 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,8 +279,7 @@ LEXOPT [aceknopr]
yyclass return OPT_YYCLASS;
\"[^"\n]*\" {
- strcpy( nmstr, yytext + 1 );
- nmstr[strlen( nmstr ) - 1] = '\0';
+ strlcpy( nmstr, yytext + 1, sizeof nmstr);
return NAME;
}
@@ -403,7 +402,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 +437,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 )