diff options
author | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-05-13 05:05:23 +0000 |
---|---|---|
committer | Jared Yanovich <jaredy@cvs.openbsd.org> | 2005-05-13 05:05:23 +0000 |
commit | e11776711108a35d66d8c57b077134bed3e1acfb (patch) | |
tree | c366ed21001071c89217312215e8d22192f536f7 /usr.bin | |
parent | b7dbd97d163566ae4a7f453d8488a8ccaa49dbd2 (diff) |
minor fixes
- some strn* to strl*
- allocation failure checks
- fix overflow in getstring()
ok otto, moritz
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/compile_et/compile_et.c | 5 | ||||
-rw-r--r-- | usr.bin/compile_et/compile_et.h | 6 | ||||
-rw-r--r-- | usr.bin/compile_et/error_table.y | 28 | ||||
-rw-r--r-- | usr.bin/compile_et/et_lex.lex.l | 6 |
4 files changed, 30 insertions, 15 deletions
diff --git a/usr.bin/compile_et/compile_et.c b/usr.bin/compile_et/compile_et.c index ad0fb14e848..7f4c9d7ed31 100644 --- a/usr.bin/compile_et/compile_et.c +++ b/usr.bin/compile_et/compile_et.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compile_et.c,v 1.11 2003/07/14 16:14:43 mho Exp $ */ +/* $OpenBSD: compile_et.c,v 1.12 2005/05/13 05:05:22 jaredy Exp $ */ /* * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). @@ -207,8 +207,7 @@ main(int argc, char **argv) else p = filename; - strncpy(Basename, p, sizeof(Basename)); - Basename[sizeof(Basename) - 1] = '\0'; + strlcpy(Basename, p, sizeof(Basename)); Basename[strcspn(Basename, ".")] = '\0'; snprintf(hfn, sizeof(hfn), "%s.h", Basename); diff --git a/usr.bin/compile_et/compile_et.h b/usr.bin/compile_et/compile_et.h index 2cb1da9bf71..3ee82db52d2 100644 --- a/usr.bin/compile_et/compile_et.h +++ b/usr.bin/compile_et/compile_et.h @@ -1,4 +1,4 @@ -/* $OpenBSD: compile_et.h,v 1.2 2001/01/29 01:57:56 niklas Exp $ */ +/* $OpenBSD: compile_et.h,v 1.3 2005/05/13 05:05:22 jaredy Exp $ */ /* * Copyright (c) 1998 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). @@ -46,6 +46,8 @@ #include <config.h> #endif +#include <err.h> +#include <errno.h> #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -81,4 +83,6 @@ do { \ } \ }while(0) +int yylex(void); + #endif /* __COMPILE_ET_H__ */ diff --git a/usr.bin/compile_et/error_table.y b/usr.bin/compile_et/error_table.y index 23ee92dd772..e362d7d5750 100644 --- a/usr.bin/compile_et/error_table.y +++ b/usr.bin/compile_et/error_table.y @@ -83,15 +83,13 @@ id : ID STRING et : ET STRING { base = name2number($2); - strncpy(name, $2, sizeof(name)); - name[sizeof(name) - 1] = '\0'; + strlcpy(name, $2, sizeof(name)); free($2); } | ET STRING STRING { base = name2number($2); - strncpy(name, $3, sizeof(name)); - name[sizeof(name) - 1] = '\0'; + strlcpy(name, $3, sizeof(name)); free($2); free($3); } @@ -108,24 +106,38 @@ statement : INDEX NUMBER | PREFIX STRING { size_t len = strlen($2) + 2; - prefix = realloc(prefix, len); + + if ((prefix = realloc(prefix, len)) == NULL) { + yyerror(strerror(errno)); + exit(1); + } strlcpy(prefix, $2, len); strlcat(prefix, "_", len); free($2); } | PREFIX { - prefix = realloc(prefix, 1); + if ((prefix = realloc(prefix, 1)) == NULL) { + yyerror(strerror(errno)); + exit(1); + } *prefix = '\0'; } | EC STRING ',' STRING { struct error_code *ec = malloc(sizeof(*ec)); - + + if (ec == NULL) { + yyerror(strerror(errno)); + exit(1); + } ec->next = NULL; ec->number = number; if(prefix && *prefix != '\0') { - asprintf (&ec->name, "%s%s", prefix, $2); + if (asprintf (&ec->name, "%s%s", prefix, $2) == -1) { + yyerror(strerror(errno)); + exit(1); + } free($2); } else ec->name = $2; diff --git a/usr.bin/compile_et/et_lex.lex.l b/usr.bin/compile_et/et_lex.lex.l index 9f9e232375a..ae7fe547172 100644 --- a/usr.bin/compile_et/et_lex.lex.l +++ b/usr.bin/compile_et/et_lex.lex.l @@ -53,7 +53,6 @@ static unsigned lineno = 1; void error_message(char *, ...); int getstring(void); -int yylex(void); %} @@ -91,7 +90,7 @@ getstring(void) int i = 0; int c; int quote = 0; - while((c = input()) != EOF){ + while(i < sizeof(x) - 1 && (c = input()) != EOF){ if(quote) { x[i++] = c; quote = 0; @@ -111,7 +110,8 @@ getstring(void) x[i++] = c; } x[i] = '\0'; - yylval.string = strdup(x); + if ((yylval.string = strdup(x)) == NULL) + err(1, NULL); return STRING; } |