diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2015-11-16 19:33:53 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2015-11-16 19:33:53 +0000 |
commit | 3e5ba3a87697f1d75a384fba7d33282b0efbc56d (patch) | |
tree | 596acb56b9a6671617dadbd62f984b37f808e5eb /sys | |
parent | 36e49efc8023dbd9e7ceb0d59d483be68658ce63 (diff) |
Replace unbounded gets() in libsa with getln() which takes a buffer size,
and convert all gets() users.
ok deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/amd64/stand/pxeboot/Makefile | 9 | ||||
-rw-r--r-- | sys/arch/aviion/stand/boot/boot.c | 4 | ||||
-rw-r--r-- | sys/arch/aviion/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/hppa/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/hppa64/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/loongson/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/octeon/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sgi/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sparc/stand/boot/boot.c | 6 | ||||
-rw-r--r-- | sys/arch/sparc/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/ofwboot/boot.c | 10 | ||||
-rw-r--r-- | sys/arch/vax/stand/boot/boot.c | 4 | ||||
-rw-r--r-- | sys/lib/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/lib/libsa/getfile.c | 4 | ||||
-rw-r--r-- | sys/lib/libsa/getln.c (renamed from sys/lib/libsa/gets.c) | 26 | ||||
-rw-r--r-- | sys/lib/libsa/stand.h | 4 |
17 files changed, 55 insertions, 48 deletions
diff --git a/sys/arch/amd64/stand/pxeboot/Makefile b/sys/arch/amd64/stand/pxeboot/Makefile index 31af8e5b581..ddf2880edea 100644 --- a/sys/arch/amd64/stand/pxeboot/Makefile +++ b/sys/arch/amd64/stand/pxeboot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.24 2015/09/02 01:52:26 yasuoka Exp $ +# $OpenBSD: Makefile,v 1.25 2015/11/16 19:33:52 miod Exp $ MAN= pxeboot.8 @@ -27,9 +27,10 @@ SRCS+= softraid.c SRCS+= boot.c cmd.c vars.c bootarg.c .PATH: ${S}/lib/libsa -SRCS+= alloc.c exit.c getchar.c getfile.c gets.c globals.c putchar.c strcmp.c \ - strlen.c strncmp.c memcmp.c memcpy.c memset.c printf.c snprintf.c \ - strerror.c strncpy.c strtol.c strtoll.c ctime.c strlcpy.c strlcat.c +SRCS+= alloc.c exit.c getchar.c getfile.c getln.c globals.c putchar.c \ + strcmp.c strlen.c strncmp.c memcmp.c memcpy.c memset.c printf.c \ + snprintf.c strerror.c strncpy.c strtol.c strtoll.c ctime.c strlcpy.c \ + strlcat.c SRCS+= aes_xts.c explicit_bzero.c hmac_sha1.c pbkdf2.c rijndael.c sha1.c SRCS+= close.c closeall.c dev.c disklabel.c dkcksum.c fstat.c ioctl.c lseek.c \ diff --git a/sys/arch/aviion/stand/boot/boot.c b/sys/arch/aviion/stand/boot/boot.c index 25f8d36a42f..fd2dc5476a8 100644 --- a/sys/arch/aviion/stand/boot/boot.c +++ b/sys/arch/aviion/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.5 2014/02/24 20:15:37 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.6 2015/11/16 19:33:52 miod Exp $ */ /*- * Copyright (c) 1995 Theo de Raadt @@ -109,7 +109,7 @@ boot(const char *args, uint bootdev, uint bootunit, uint bootlun) for (;;) { if (ask != 0) { printf("boot: "); - gets(line); + getln(line, sizeof line); if (line[0] == '\0') continue; diff --git a/sys/arch/aviion/stand/libsa/Makefile b/sys/arch/aviion/stand/libsa/Makefile index eff44aa59e6..977ba6c9721 100644 --- a/sys/arch/aviion/stand/libsa/Makefile +++ b/sys/arch/aviion/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2014/11/19 20:01:35 miod Exp $ +# $OpenBSD: Makefile,v 1.7 2015/11/16 19:33:52 miod Exp $ LIB=sa @@ -12,7 +12,7 @@ S=${.CURDIR}/../../../.. SRCS= clock.c delay.S exec.c fault.c parse_args.c setjmp.S .PATH: ${S}/lib/libsa -SRCS+= alloc.c memcpy.c exit.c getfile.c gets.c globals.c loadfile.c \ +SRCS+= alloc.c memcpy.c exit.c getfile.c getln.c globals.c loadfile.c \ printf.c strerror.c memset.c memcmp.c strncpy.c strcmp.c strlen.c \ strlcpy.c strlcat.c snprintf.c strchr.c strtol.c \ close.c closeall.c dev.c dkcksum.c \ diff --git a/sys/arch/hppa/stand/libsa/Makefile b/sys/arch/hppa/stand/libsa/Makefile index 71eeca4469b..58cc74111a4 100644 --- a/sys/arch/hppa/stand/libsa/Makefile +++ b/sys/arch/hppa/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.19 2014/07/13 09:26:08 jasper Exp $ +# $OpenBSD: Makefile,v 1.20 2015/11/16 19:33:52 miod Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -20,7 +20,7 @@ SRCS= machdep.c pdc.c itecons.c dev_hppa.c time.c \ ct.c dk.c lf.c lif.c cmd_hppa.c loadfile.c elf32.c elf64.c # stand routines -SRCS+= alloc.c exit.c getfile.c gets.c getchar.c globals.c \ +SRCS+= alloc.c exit.c getfile.c getln.c getchar.c globals.c \ printf.c putchar.c strerror.c strtol.c strchr.c ctime.c snprintf.c # io routines diff --git a/sys/arch/hppa64/stand/libsa/Makefile b/sys/arch/hppa64/stand/libsa/Makefile index 8ce85ee55e1..09595e17907 100644 --- a/sys/arch/hppa64/stand/libsa/Makefile +++ b/sys/arch/hppa64/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2014/07/13 09:26:08 jasper Exp $ +# $OpenBSD: Makefile,v 1.6 2015/11/16 19:33:52 miod Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -21,7 +21,7 @@ SRCS= machdep.c pdc.c itecons.c dev_hppa64.c time.c \ ct.c dk.c lf.c lif.c cmd_hppa64.c # stand routines -SRCS+= alloc.c exit.c getfile.c gets.c getchar.c globals.c \ +SRCS+= alloc.c exit.c getfile.c getln.c getchar.c globals.c \ printf.c putchar.c strerror.c strtol.c strchr.c ctime.c loadfile.c \ snprintf.c diff --git a/sys/arch/loongson/stand/libsa/Makefile b/sys/arch/loongson/stand/libsa/Makefile index de176e7e5d0..844b3333cfb 100644 --- a/sys/arch/loongson/stand/libsa/Makefile +++ b/sys/arch/loongson/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2014/07/13 09:26:08 jasper Exp $ +# $OpenBSD: Makefile,v 1.7 2015/11/16 19:33:52 miod Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -16,7 +16,7 @@ CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdinc -mno-abicalls -D_NO_ABICALLS \ -I${.OBJDIR} # stand routines -SRCS= alloc.c cons.c ctime.c exit.c getchar.c getfile.c gets.c globals.c \ +SRCS= alloc.c cons.c ctime.c exit.c getchar.c getfile.c getln.c globals.c \ memcmp.c memcpy.c memset.c printf.c putchar.c \ snprintf.c strchr.c strcmp.c strerror.c strncmp.c strncpy.c strtol.c diff --git a/sys/arch/octeon/stand/libsa/Makefile b/sys/arch/octeon/stand/libsa/Makefile index 3b8c9eff256..ed14a0e2aba 100644 --- a/sys/arch/octeon/stand/libsa/Makefile +++ b/sys/arch/octeon/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2014/07/13 09:26:08 jasper Exp $ +# $OpenBSD: Makefile,v 1.5 2015/11/16 19:33:52 miod Exp $ .include "${.CURDIR}/../Makefile.inc" @@ -16,7 +16,7 @@ CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdinc -mno-abicalls -D_NO_ABICALLS \ -I${.OBJDIR} # stand routines -SRCS= alloc.c cons.c ctime.c exit.c getchar.c getfile.c gets.c globals.c \ +SRCS= alloc.c cons.c ctime.c exit.c getchar.c getfile.c getln.c globals.c \ memcmp.c memcpy.c memset.c printf.c putchar.c \ snprintf.c strchr.c strcmp.c strerror.c strncmp.c strncpy.c strtol.c diff --git a/sys/arch/sgi/stand/libsa/Makefile b/sys/arch/sgi/stand/libsa/Makefile index 3ad2bb84ee5..67608298e04 100644 --- a/sys/arch/sgi/stand/libsa/Makefile +++ b/sys/arch/sgi/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.8 2013/01/01 18:49:33 miod Exp $ +# $OpenBSD: Makefile,v 1.9 2015/11/16 19:33:52 miod Exp $ LIB= sa @@ -17,7 +17,7 @@ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD ${STANDALONE} CPPFLAGS+= ${LIBSA_CPPFLAGS} # stand routines -SRCS= alloc.c exit.c getfile.c gets.c globals.c \ +SRCS= alloc.c exit.c getfile.c getln.c globals.c \ memcmp.c memcpy.c memset.c printf.c snprintf.c strerror.c strncpy.c # io routines diff --git a/sys/arch/sparc/stand/boot/boot.c b/sys/arch/sparc/stand/boot/boot.c index 14686a7f356..b08af2ff65c 100644 --- a/sys/arch/sparc/stand/boot/boot.c +++ b/sys/arch/sparc/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.14 2015/05/19 20:42:11 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.15 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: boot.c,v 1.2 1997/09/14 19:27:21 pk Exp $ */ /*- @@ -357,11 +357,11 @@ main(int argc, char *argv[]) for (;;) { if (prom_boothow & RB_ASKNAME) { printf("device[%s]: ", prom_bootdevice); - gets(dbuf); + getln(dbuf, sizeof dbuf); if (dbuf[0]) prom_bootdevice = dbuf; printf("boot: "); - gets(fbuf); + getln(fbuf, sizeof fbuf); if (fbuf[0]) file = fbuf; } diff --git a/sys/arch/sparc/stand/libsa/Makefile b/sys/arch/sparc/stand/libsa/Makefile index b2c0b01f3a0..ed3bb5350c4 100644 --- a/sys/arch/sparc/stand/libsa/Makefile +++ b/sys/arch/sparc/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.9 2014/11/19 20:01:36 miod Exp $ +# $OpenBSD: Makefile,v 1.10 2015/11/16 19:33:52 miod Exp $ LIB= sa @@ -10,7 +10,7 @@ CFLAGS= -fno-pie -O2 -D_STANDALONE -D__INTERNAL_LIBSA_CREAD \ -I${.CURDIR}/../../../../lib/libsa # stand routines -SRCS= alloc.c exit.c getfile.c gets.c globals.c \ +SRCS= alloc.c exit.c getfile.c getln.c globals.c \ memcmp.c memcpy.c memset.c printf.c snprintf.c strerror.c strncpy.c # io routines diff --git a/sys/arch/sparc64/stand/libsa/Makefile b/sys/arch/sparc64/stand/libsa/Makefile index 08a8735610b..a3e6d4126a1 100644 --- a/sys/arch/sparc64/stand/libsa/Makefile +++ b/sys/arch/sparc64/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.10 2014/11/19 20:01:36 miod Exp $ +# $OpenBSD: Makefile,v 1.11 2015/11/16 19:33:52 miod Exp $ LIB= sa @@ -16,7 +16,7 @@ CFLAGS= ${CEXTRAFLAGS} ${AFLAGS} -O2 -D__INTERNAL_LIBSA_CREAD -nostdinc \ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD # stand routines -SRCS= alloc.c exit.c getfile.c gets.c globals.c \ +SRCS= alloc.c exit.c getfile.c getln.c globals.c \ memcmp.c memcpy.c memset.c printf.c snprintf.c strerror.c strncpy.c # io routines diff --git a/sys/arch/sparc64/stand/ofwboot/boot.c b/sys/arch/sparc64/stand/ofwboot/boot.c index 053c9c8c744..198dab9deff 100644 --- a/sys/arch/sparc64/stand/ofwboot/boot.c +++ b/sys/arch/sparc64/stand/ofwboot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.23 2014/12/11 10:52:07 stsp Exp $ */ +/* $OpenBSD: boot.c,v 1.24 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: boot.c,v 1.3 2001/05/31 08:55:19 mrg Exp $ */ /* * Copyright (c) 1997, 1999 Eduardo E. Horvath. All rights reserved. @@ -380,11 +380,11 @@ main() /* * case 1: boot net -a - * -> gets loop + * -> getln loop * case 2: boot net kernel [options] - * -> boot kernel, gets loop + * -> boot kernel, getln loop * case 3: boot net [options] - * -> iterate boot list, gets loop + * -> iterate boot list, getln loop */ bootlp = kernels; @@ -415,7 +415,7 @@ main() } if (!bootlp) { printf("Boot: "); - gets(bootline); + getln(bootline, sizeof bootline); if (parseargs(bootline, &boothowto) == -1) continue; if (!*bootline) { diff --git a/sys/arch/vax/stand/boot/boot.c b/sys/arch/vax/stand/boot/boot.c index 8e99ec0c46f..ebd0823f829 100644 --- a/sys/arch/vax/stand/boot/boot.c +++ b/sys/arch/vax/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.25 2014/02/19 22:13:53 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.26 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: boot.c,v 1.18 2002/05/31 15:58:26 ragge Exp $ */ /*- * Copyright (c) 1982, 1986 The Regents of the University of California. @@ -154,7 +154,7 @@ Xmain(void) char *c, *d; printf("> "); - gets(line); + getln(line, sizeof line); c = line; while (*c == ' ') diff --git a/sys/lib/libsa/Makefile b/sys/lib/libsa/Makefile index 0324e76765f..5e722d49328 100644 --- a/sys/lib/libsa/Makefile +++ b/sys/lib/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.27 2015/09/18 13:42:31 miod Exp $ +# $OpenBSD: Makefile,v 1.28 2015/11/16 19:33:52 miod Exp $ # $NetBSD: Makefile,v 1.13 1996/10/02 16:19:51 ws Exp $ LIB= sa @@ -24,7 +24,7 @@ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD .endif # stand routines -SRCS+= alloc.c memcpy.c exit.c getfile.c getchar.c gets.c globals.c \ +SRCS+= alloc.c memcpy.c exit.c getfile.c getchar.c getln.c globals.c \ printf.c putchar.c snprintf.c strerror.c strcmp.c memset.c memcmp.c \ strncpy.c strncmp.c strchr.c diff --git a/sys/lib/libsa/getfile.c b/sys/lib/libsa/getfile.c index f6131d1e4f1..be134430d4c 100644 --- a/sys/lib/libsa/getfile.c +++ b/sys/lib/libsa/getfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getfile.c,v 1.6 2014/11/19 20:28:56 miod Exp $ */ +/* $OpenBSD: getfile.c,v 1.7 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: getfile.c,v 1.6 1996/10/14 04:49:21 cgd Exp $ */ /*- @@ -45,7 +45,7 @@ getfile(const char *prompt, int mode) do { printf("%s: ", prompt); - gets(buf); + getln(buf, sizeof buf); if (buf[0] == CTRL('d') && buf[1] == 0) return (-1); } while ((fd = open(buf, mode)) < 0); diff --git a/sys/lib/libsa/gets.c b/sys/lib/libsa/getln.c index a724a3c14ca..7dae1e3aeda 100644 --- a/sys/lib/libsa/gets.c +++ b/sys/lib/libsa/getln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gets.c,v 1.4 2003/08/11 06:23:09 deraadt Exp $ */ +/* $OpenBSD: getln.c,v 1.1 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: gets.c,v 1.5.2.1 1995/10/13 19:54:26 pk Exp $ */ /*- @@ -35,12 +35,16 @@ #include "stand.h" void -gets(char *buf) +getln(char *buf, size_t bufsiz) { int c; - char *lp; + char *lp, *ep; - for (lp = buf;;) + if (bufsiz == 0) + return; + ep = buf + bufsiz - 1; + + for (lp = buf; ;) switch (c = getchar() & 0177) { case '\n': case '\r': @@ -62,24 +66,26 @@ gets(char *buf) --lp; break; #endif - case 'r'&037: { - char *p; + case 'r' & 037: + { + char *p; putchar('\n'); for (p = buf; p < lp; ++p) putchar(*p); break; - } + } #if AT_ERASE case '@': #endif - case 'u'&037: - case 'w'&037: + case 'u' & 037: + case 'w' & 037: lp = buf; putchar('\n'); break; default: - *lp++ = c; + if (lp != ep) + *lp++ = c; putchar(c); } /*NOTREACHED*/ diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h index a56a2e96b45..abc95875614 100644 --- a/sys/lib/libsa/stand.h +++ b/sys/lib/libsa/stand.h @@ -1,4 +1,4 @@ -/* $OpenBSD: stand.h,v 1.61 2015/09/02 01:52:26 yasuoka Exp $ */ +/* $OpenBSD: stand.h,v 1.62 2015/11/16 19:33:52 miod Exp $ */ /* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */ /*- @@ -138,7 +138,7 @@ void printf(const char *, ...); int snprintf(char *, size_t, const char *, ...); void vprintf(const char *, __va_list); void twiddle(void); -void gets(char *); +void getln(char *, size_t); __dead void panic(const char *, ...) __attribute__((noreturn)); __dead void _rtt(void) __attribute__((noreturn)); #define bzero(s,n) ((void)memset((s),0,(n))) |