summaryrefslogtreecommitdiff
path: root/sys/stand/boot
diff options
context:
space:
mode:
authorTom Cosgrove <tom@cvs.openbsd.org>2004-06-24 16:39:00 +0000
committerTom Cosgrove <tom@cvs.openbsd.org>2004-06-24 16:39:00 +0000
commitea4a42f5c20e11e6e2b2c8654e9034ef8e9bf383 (patch)
treea258d330a53dca62f58436b2ee3c24a7e4a5422d /sys/stand/boot
parent0d7046573b3bbef90fb11951a776a2da7f844a59 (diff)
If a line in boot.conf is too long for our buffer, stop before we
overrun the buffer, print an error message, then stop processing boot.conf. Also change name of variable "eof" to "rc", since it's not just for eof. ok weingart@
Diffstat (limited to 'sys/stand/boot')
-rw-r--r--sys/stand/boot/cmd.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/sys/stand/boot/cmd.c b/sys/stand/boot/cmd.c
index 389d21dee3a..258dde30634 100644
--- a/sys/stand/boot/cmd.c
+++ b/sys/stand/boot/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.52 2003/11/08 19:17:28 jmc Exp $ */
+/* $OpenBSD: cmd.c,v 1.53 2004/06/24 16:38:59 tom Exp $ */
/*
* Copyright (c) 1997-1999 Michael Shalayeff
@@ -94,7 +94,7 @@ read_conf(void)
#ifndef INSECURE
struct stat sb;
#endif
- int fd, eof = 0;
+ int fd, rc = 0;
if ((fd = open(qualify(cmd.conf), 0)) < 0) {
if (errno != ENOENT && errno != ENXIO) {
@@ -119,18 +119,29 @@ read_conf(void)
cmd.cmd = NULL;
do {
- eof = read(fd, p, 1);
- } while (eof > 0 && *p++ != '\n');
+ rc = read(fd, p, 1);
+ } while (rc > 0 && *p++ != '\n' &&
+ (p-cmd_buf) < sizeof(cmd_buf));
- if (eof < 0)
+ if (rc < 0)
printf("%s: %s\n", cmd.path, strerror(errno));
- else
- *--p = '\0';
+ else {
+ p--; /* Get back to last character */
+
+ if (*p != '\n') { /* Line was too long */
+ printf("%s: line too long\n", cmd.path);
+
+ /* Don't want to run the truncated command */
+ rc = -1;
+ }
+
+ *p = '\0';
+ }
- } while (eof > 0 && !(eof = docmd()));
+ } while (rc > 0 && !(rc = docmd()));
close(fd);
- return eof;
+ return rc;
}
static int