diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-04-06 22:02:06 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-04-06 22:02:06 +0000 |
commit | acada70b773c4b2607515423324fcf6cba528b58 (patch) | |
tree | db275642b9437ab0c046e65c01f791765521bdbc /usr.bin/tn3270 | |
parent | edd036bcd309a616f07f293aa53f9d31838370f9 (diff) |
no strcpy. no strcat. no sprintf. some from deraadt@
prototype for malloc from stdlib.h, not our own wrong one (in each function!).
use strdup, don't roll our own. this program is a real piece of work.
Diffstat (limited to 'usr.bin/tn3270')
-rw-r--r-- | usr.bin/tn3270/api/api_exch.c | 6 | ||||
-rw-r--r-- | usr.bin/tn3270/ascii/map3270.c | 24 | ||||
-rw-r--r-- | usr.bin/tn3270/sys_curses/system.c | 10 | ||||
-rw-r--r-- | usr.bin/tn3270/sys_curses/telextrn.h | 8 | ||||
-rw-r--r-- | usr.bin/tn3270/sys_curses/termout.c | 12 | ||||
-rw-r--r-- | usr.bin/tn3270/tools/mkhits/dohits.c | 8 | ||||
-rw-r--r-- | usr.bin/tn3270/tools/mkmake.y | 24 |
7 files changed, 37 insertions, 55 deletions
diff --git a/usr.bin/tn3270/api/api_exch.c b/usr.bin/tn3270/api/api_exch.c index 7fb3d5f7a4d..54c7b2481ec 100644 --- a/usr.bin/tn3270/api/api_exch.c +++ b/usr.bin/tn3270/api/api_exch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: api_exch.c,v 1.3 2003/04/04 22:13:10 deraadt Exp $ */ +/* $OpenBSD: api_exch.c,v 1.4 2003/04/06 22:02:05 tedu Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)api_exch.c 4.2 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$OpenBSD: api_exch.c,v 1.3 2003/04/04 22:13:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: api_exch.c,v 1.4 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ #include <stdio.h> @@ -417,7 +417,7 @@ int sock_number; char *ourname; { sock = sock_number; - (void) strcpy(whoarewe, ourname); /* For error messages */ + (void) strlcpy(whoarewe, ourname, sizeof whoarewe); /* For error messages */ my_sequence = your_sequence = 0; diff --git a/usr.bin/tn3270/ascii/map3270.c b/usr.bin/tn3270/ascii/map3270.c index eddbce18569..fc225c011d4 100644 --- a/usr.bin/tn3270/ascii/map3270.c +++ b/usr.bin/tn3270/ascii/map3270.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map3270.c,v 1.5 2003/04/04 22:13:10 deraadt Exp $ */ +/* $OpenBSD: map3270.c,v 1.6 2003/04/06 22:02:05 tedu Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)map3270.c 4.2 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$OpenBSD: map3270.c,v 1.5 2003/04/04 22:13:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: map3270.c,v 1.6 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ /* This program reads a description file, somewhat like /etc/termcap, @@ -60,11 +60,8 @@ static char rcsid[] = "$OpenBSD: map3270.c,v 1.5 2003/04/04 22:13:10 deraadt Exp #include <stdio.h> #include <ctype.h> -#if defined(unix) -#include <strings.h> -#else /* defined(unix) */ +#include <stdlib.h> #include <string.h> -#endif /* defined(unix) */ #define IsPrint(c) ((isprint(c) && !isspace(c)) || ((c) == ' ')) @@ -476,9 +473,7 @@ static void FreeState(pState) state *pState; { - extern int free(); - - free((char *)pState); + free(pState); } @@ -486,7 +481,6 @@ static state * GetState() { state *pState; - extern char *malloc(); pState = (state *) malloc(sizeof (state)); @@ -827,14 +821,6 @@ char *keybdPointer; Return(0); } -char * -strsave(string) -char *string; -{ - return (strdup(string)); -} - - /* * InitControl - our interface to the outside. What we should * do is figure out keyboard (or terminal) type, set up file pointer @@ -865,7 +851,7 @@ int (*translator)(); /* Translates ascii string to integer */ * out of a static area. So, save the keyboard name. */ if (keybdPointer) { - keybdPointer = strsave(keybdPointer); + keybdPointer = strdup(keybdPointer); } environPointer = getenv("MAP3270"); if (environPointer diff --git a/usr.bin/tn3270/sys_curses/system.c b/usr.bin/tn3270/sys_curses/system.c index f7b6f2539d9..1ed0ea8eac6 100644 --- a/usr.bin/tn3270/sys_curses/system.c +++ b/usr.bin/tn3270/sys_curses/system.c @@ -1,4 +1,4 @@ -/* $OpenBSD: system.c,v 1.12 2003/04/04 22:13:10 deraadt Exp $ */ +/* $OpenBSD: system.c,v 1.13 2003/04/06 22:02:05 tedu Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)system.c 4.5 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$OpenBSD: system.c,v 1.12 2003/04/04 22:13:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: system.c,v 1.13 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -697,8 +697,10 @@ char *argv[]; fprintf(stderr, "Local hostname too large; using 'localhost'.\n"); strlcpy(sockNAME, "localhost", sizeof sockNAME); } - sprintf(sockNAME+strlen(sockNAME), ":%u", ntohs(server.sin_port)); - sprintf(sockNAME+strlen(sockNAME), ":%s", keyname); + snprintf(sockNAME+strlen(sockNAME), sizeof(sockNAME) - strlen(sockNAME), + ":%u", ntohs(server.sin_port)); + snprintf(sockNAME+strlen(sockNAME), sizeof(sockNAME) - strlen(sockNAME), + ":%s", keyname); if (whereAPI == 0) { char **ptr, **nextenv; diff --git a/usr.bin/tn3270/sys_curses/telextrn.h b/usr.bin/tn3270/sys_curses/telextrn.h index e0ccda4c6d0..ca9cacb13a0 100644 --- a/usr.bin/tn3270/sys_curses/telextrn.h +++ b/usr.bin/tn3270/sys_curses/telextrn.h @@ -1,4 +1,4 @@ -/* * $OpenBSD: telextrn.h,v 1.2 1996/06/26 05:41:31 deraadt Exp $*/ +/* * $OpenBSD: telextrn.h,v 1.3 2003/04/06 22:02:05 tedu Exp $*/ /*- * Copyright (c) 1988 The Regents of the University of California. * All rights reserved. @@ -64,9 +64,3 @@ extern void ExitPerror(), setcommandmode(); -/* - * Pieces exported from other random locations. - */ - -extern char - *strsave(); diff --git a/usr.bin/tn3270/sys_curses/termout.c b/usr.bin/tn3270/sys_curses/termout.c index 252f8be5124..9f6a1735f2a 100644 --- a/usr.bin/tn3270/sys_curses/termout.c +++ b/usr.bin/tn3270/sys_curses/termout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: termout.c,v 1.9 2003/04/04 22:13:10 deraadt Exp $ */ +/* $OpenBSD: termout.c,v 1.10 2003/04/06 22:02:05 tedu Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)termout.c 4.3 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$OpenBSD: termout.c,v 1.9 2003/04/04 22:13:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: termout.c,v 1.10 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ #if defined(unix) @@ -683,16 +683,16 @@ InitTerminal() */ signal(SIGTSTP, SIG_DFL); if ((myKS = tigetstr("smkx")) != 0) { - myKS = strsave(myKS); + myKS = strdup(myKS); StringToTerminal(myKS); } if ((myKE = tigetstr("rmkx")) != 0) { - myKE = strsave(myKE); + myKE = strdup(myKE); } /* XXX - why? */ if (tigetstr("bold") && tigetstr("sgr0")) { - enter_standout_mode = strsave(tigetstr("bold")); - exit_standout_mode = strsave(tigetstr("sgr0")); + enter_standout_mode = strdup(tigetstr("bold")); + exit_standout_mode = strdup(tigetstr("sgr0")); } #endif DoARefresh(); diff --git a/usr.bin/tn3270/tools/mkhits/dohits.c b/usr.bin/tn3270/tools/mkhits/dohits.c index c4cfee4fa79..55e3b957ca7 100644 --- a/usr.bin/tn3270/tools/mkhits/dohits.c +++ b/usr.bin/tn3270/tools/mkhits/dohits.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dohits.c,v 1.5 2003/04/04 22:13:10 deraadt Exp $ */ +/* $OpenBSD: dohits.c,v 1.6 2003/04/06 22:02:05 tedu Exp $ */ /*- * Copyright (c) 1988 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)dohits.c 4.2 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$OpenBSD: dohits.c,v 1.5 2003/04/04 22:13:10 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: dohits.c,v 1.6 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ /* @@ -107,8 +107,8 @@ int value; this->hits = NULL; *item = this; this->value = value; - strcpy(this->name, first); - strcpy(this->name+strlen(this->name), second); + strlcpy(this->name, first, sizeof this->name); + strlcpy(this->name+strlen(this->name), second, sizeof this->name); } void diff --git a/usr.bin/tn3270/tools/mkmake.y b/usr.bin/tn3270/tools/mkmake.y index ae1a4c1f954..d584d3bc73c 100644 --- a/usr.bin/tn3270/tools/mkmake.y +++ b/usr.bin/tn3270/tools/mkmake.y @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)mkmake.y 4.2 (Berkeley) 4/26/91";*/ -static char rcsid[] = "$Id: mkmake.y,v 1.2 2000/07/06 08:51:06 deraadt Exp $"; +static char rcsid[] = "$Id: mkmake.y,v 1.3 2003/04/06 22:02:05 tedu Exp $"; #endif /* not lint */ typedef struct string { @@ -504,16 +504,16 @@ same_t *t2; { if (same_singleton(t1) && same_singleton(t2)) { - int length = strlen(t1->string->string)+strlen(t2->string->string); - char *buffer = malloc(length+1); + int length = strlen(t1->string->string)+strlen(t2->string->string) + 1; + char *buffer = malloc(length); same_t *value; if (buffer == 0) { yyerror("No space to merge strings in same_merge!"); exit(1); } - strcpy(buffer, t1->string->string); - strcat(buffer, t2->string->string); + strlcpy(buffer, t1->string->string, length); + strlcat(buffer, t2->string->string, length); value = same_item(string_lookup(buffer)); free(buffer); return value; @@ -760,18 +760,18 @@ same_t * variable(var_name) same_t *var_name; { - int length = strlen(var_name->string->string); + int length = strlen(var_name->string->string) + 3 + 1; same_t *resolved; char *newname; - if ((newname = malloc(length+1+3)) == 0) { + if ((newname = malloc(length)) == 0) { fprintf("Out of space for a variable name.\n"); exit(1); } newname[0] = '$'; newname[1] = '{'; - strcpy(newname+2, var_name->string->string); - strcat(newname, "}"); + strlcpy(newname+2, var_name->string->string, length - 2); + strlcat(newname, "}", length); resolved = same_item(string_lookup(newname)); free(newname); @@ -783,17 +783,17 @@ same_t * shell_variable(var_name) same_t *var_name; { - int length = strlen(var_name->string->string); + int length = strlen(var_name->string->string) + 2 + 1; same_t *resolved; char *newname; - if ((newname = malloc(length+1+2)) == 0) { + if ((newname = malloc(length)) == 0) { fprintf("Out of space for a variable name.\n"); exit(1); } newname[0] = '$'; newname[1] = '$'; - strcpy(newname+2, var_name->string->string); + strlcpy(newname+2, var_name->string->string, length - 2); resolved = same_item(string_lookup(newname)); free(newname); |