> I want correct typing mistakes when booting from softraid crypto disks.
> Can we handle at least the backspace key, plz^Hease? :)
This calls for a libsa gets() replacement, which will honour bounds.
What about the plumbing diff below, so that softraid-capable bootblocks
can use the new getln() routine instead of rolling their own?
Index: arch/amd64/stand/pxeboot/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/amd64/stand/pxeboot/Makefile,v
retrieving revision 1.24
diff -u -p -r1.24 Makefile
--- arch/amd64/stand/pxeboot/Makefile 2 Sep 2015 01:52:26 -0000 1.24
+++ arch/amd64/stand/pxeboot/Makefile 30 Oct 2015 16:27:31 -0000
@@ -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 \
Index: arch/aviion/stand/boot/boot.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/aviion/stand/boot/boot.c,v
retrieving revision 1.5
diff -u -p -r1.5 boot.c
--- arch/aviion/stand/boot/boot.c 24 Feb 2014 20:15:37 -0000 1.5
+++ arch/aviion/stand/boot/boot.c 30 Oct 2015 16:27:31 -0000
@@ -109,7 +109,7 @@ boot(const char *args, uint bootdev, uin
for (;;) {
if (ask != 0) {
printf("boot: ");
- gets(line);
+ getln(line, sizeof line);
if (line[0] == '\0')
continue;
Index: arch/aviion/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/aviion/stand/libsa/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- arch/aviion/stand/libsa/Makefile 19 Nov 2014 20:01:35 -0000 1.6
+++ arch/aviion/stand/libsa/Makefile 30 Oct 2015 16:27:31 -0000
@@ -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 \
Index: arch/hppa/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/hppa/stand/libsa/Makefile,v
retrieving revision 1.19
diff -u -p -r1.19 Makefile
--- arch/hppa/stand/libsa/Makefile 13 Jul 2014 09:26:08 -0000 1.19
+++ arch/hppa/stand/libsa/Makefile 30 Oct 2015 16:27:31 -0000
@@ -20,7 +20,7 @@ SRCS= machdep.c pdc.c itecons.c dev_hppa
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
Index: arch/hppa64/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/hppa64/stand/libsa/Makefile,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile
--- arch/hppa64/stand/libsa/Makefile 13 Jul 2014 09:26:08 -0000 1.5
+++ arch/hppa64/stand/libsa/Makefile 30 Oct 2015 16:27:31 -0000
@@ -21,7 +21,7 @@ SRCS= machdep.c pdc.c itecons.c dev_hppa
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
Index: arch/loongson/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/loongson/stand/libsa/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- arch/loongson/stand/libsa/Makefile 13 Jul 2014 09:26:08 -0000 1.6
+++ arch/loongson/stand/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -16,7 +16,7 @@ CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdi
-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
Index: arch/octeon/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/octeon/stand/libsa/Makefile,v
retrieving revision 1.4
diff -u -p -r1.4 Makefile
--- arch/octeon/stand/libsa/Makefile 13 Jul 2014 09:26:08 -0000 1.4
+++ arch/octeon/stand/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -16,7 +16,7 @@ CFLAGS+= ${CEXTRAFLAGS} ${SAABI} -nostdi
-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
Index: arch/sgi/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/sgi/stand/libsa/Makefile,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile
--- arch/sgi/stand/libsa/Makefile 1 Jan 2013 18:49:33 -0000 1.8
+++ arch/sgi/stand/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -17,7 +17,7 @@ CPPFLAGS+= -D__INTERNAL_LIBSA_CREAD ${ST
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
Index: arch/sparc/stand/boot/boot.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc/stand/boot/boot.c,v
retrieving revision 1.14
diff -u -p -r1.14 boot.c
--- arch/sparc/stand/boot/boot.c 19 May 2015 20:42:11 -0000 1.14
+++ arch/sparc/stand/boot/boot.c 30 Oct 2015 16:27:32 -0000
@@ -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;
}
Index: arch/sparc/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc/stand/libsa/Makefile,v
retrieving revision 1.9
diff -u -p -r1.9 Makefile
--- arch/sparc/stand/libsa/Makefile 19 Nov 2014 20:01:36 -0000 1.9
+++ arch/sparc/stand/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -10,7 +10,7 @@ CFLAGS= -fno-pie -O2 -D_STANDALONE -D__I
-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
Index: arch/sparc64/stand/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/stand/libsa/Makefile,v
retrieving revision 1.10
diff -u -p -r1.10 Makefile
--- arch/sparc64/stand/libsa/Makefile 19 Nov 2014 20:01:36 -0000 1.10
+++ arch/sparc64/stand/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -16,7 +16,7 @@ CFLAGS= ${CEXTRAFLAGS} ${AFLAGS} -O2 -D_
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
Index: arch/sparc64/stand/ofwboot/boot.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/sparc64/stand/ofwboot/boot.c,v
retrieving revision 1.23
diff -u -p -r1.23 boot.c
--- arch/sparc64/stand/ofwboot/boot.c 11 Dec 2014 10:52:07 -0000 1.23
+++ arch/sparc64/stand/ofwboot/boot.c 30 Oct 2015 16:27:32 -0000
@@ -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) {
Index: arch/vax/stand/boot/boot.c
===================================================================
RCS file: /OpenBSD/src/sys/arch/vax/stand/boot/boot.c,v
retrieving revision 1.25
diff -u -p -r1.25 boot.c
--- arch/vax/stand/boot/boot.c 19 Feb 2014 22:13:53 -0000 1.25
+++ arch/vax/stand/boot/boot.c 30 Oct 2015 16:27:32 -0000
@@ -154,7 +154,7 @@ Xmain(void)
char *c, *d;
printf("> ");
- gets(line);
+ getln(line, sizeof line);
c = line;
while (*c == ' ')
Index: lib/libsa/Makefile
===================================================================
RCS file: /OpenBSD/src/sys/lib/libsa/Makefile,v
retrieving revision 1.27
diff -u -p -r1.27 Makefile
--- lib/libsa/Makefile 18 Sep 2015 13:42:31 -0000 1.27
+++ lib/libsa/Makefile 30 Oct 2015 16:27:32 -0000
@@ -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
Index: lib/libsa/getfile.c
===================================================================
RCS file: /OpenBSD/src/sys/lib/libsa/getfile.c,v
retrieving revision 1.6
diff -u -p -r1.6 getfile.c
--- lib/libsa/getfile.c 19 Nov 2014 20:28:56 -0000 1.6
+++ lib/libsa/getfile.c 30 Oct 2015 16:27:32 -0000
@@ -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);
Index: lib/libsa/getln.c
===================================================================
RCS file: lib/libsa/getln.c
diff -N lib/libsa/getln.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libsa/getln.c 30 Oct 2015 16:27:32 -0000
@@ -0,0 +1,92 @@
+/* $OpenBSD$ */
+/* $NetBSD: gets.c,v 1.5.2.1 1995/10/13 19:54:26 pk Exp $ */
+
+/*-
+ * Copyright (c) 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)gets.c 8.1 (Berkeley) 6/11/93
+ */
+
+#include "stand.h"
+
+void
+getln(char *buf, size_t bufsiz)
+{
+ int c;
+ char *lp, *ep;
+
+ if (bufsiz == 0)
+ return;
+ ep = buf + bufsiz - 1;
+
+ for (lp = buf; ;)
+ switch (c = getchar() & 0177) {
+ case '\n':
+ case '\r':
+ *lp = '\0';
+ putchar('\n');
+ return;
+ case '\b':
+ case '\177':
+ if (lp > buf) {
+ lp--;
+ putchar('\b');
+ putchar(' ');
+ putchar('\b');
+ }
+ break;
+#if HASH_ERASE
+ case '#':
+ if (lp > buf)
+ --lp;
+ break;
+#endif
+ 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:
+ lp = buf;
+ putchar('\n');
+ break;
+ default:
+ if (lp != ep)
+ *lp++ = c;
+ putchar(c);
+ }
+ /*NOTREACHED*/
+}
Index: lib/libsa/gets.c
===================================================================
RCS file: lib/libsa/gets.c
diff -N lib/libsa/gets.c
--- lib/libsa/gets.c 11 Aug 2003 06:23:09 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,86 +0,0 @@
-/* $OpenBSD: gets.c,v 1.4 2003/08/11 06:23:09 deraadt Exp $ */
-/* $NetBSD: gets.c,v 1.5.2.1 1995/10/13 19:54:26 pk Exp $ */
-
-/*-
- * Copyright (c) 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)gets.c 8.1 (Berkeley) 6/11/93
- */
-
-#include "stand.h"
-
-void
-gets(char *buf)
-{
- int c;
- char *lp;
-
- for (lp = buf;;)
- switch (c = getchar() & 0177) {
- case '\n':
- case '\r':
- *lp = '\0';
- putchar('\n');
- return;
- case '\b':
- case '\177':
- if (lp > buf) {
- lp--;
- putchar('\b');
- putchar(' ');
- putchar('\b');
- }
- break;
-#if HASH_ERASE
- case '#':
- if (lp > buf)
- --lp;
- break;
-#endif
- 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:
- lp = buf;
- putchar('\n');
- break;
- default:
- *lp++ = c;
- putchar(c);
- }
- /*NOTREACHED*/
-}
Index: lib/libsa/stand.h
===================================================================
RCS file: /OpenBSD/src/sys/lib/libsa/stand.h,v
retrieving revision 1.61
diff -u -p -r1.61 stand.h
--- lib/libsa/stand.h 2 Sep 2015 01:52:26 -0000 1.61
+++ lib/libsa/stand.h 30 Oct 2015 16:27:32 -0000
@@ -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)))