diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-05-31 17:09:18 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-05-31 17:09:18 +0000 |
commit | d11806554306cb0fcf5bcd836a423cb9a85253e0 (patch) | |
tree | 0bf41afa870fd1289e911372bdc296bcd0d9a9eb /sbin | |
parent | 1b8c1d72284ea1b739573cb51090d4f9ce6abaa0 (diff) |
Cleaner loop structure when reading panic string from the core image.
We now check the return value of KREAD() which may solve PR 1254.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/savecore/savecore.c | 22 | ||||
-rw-r--r-- | sbin/savecore/savecore_old.c | 25 |
2 files changed, 26 insertions, 21 deletions
diff --git a/sbin/savecore/savecore.c b/sbin/savecore/savecore.c index 53fec980979..419a07bb4e7 100644 --- a/sbin/savecore/savecore.c +++ b/sbin/savecore/savecore.c @@ -1,4 +1,4 @@ -/* $OpenBSD: savecore.c,v 1.19 1999/08/16 18:38:50 art Exp $ */ +/* $OpenBSD: savecore.c,v 1.20 2000/05/31 17:09:17 millert Exp $ */ /* $NetBSD: savecore.c,v 1.26 1996/03/18 21:16:05 leo Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: savecore.c,v 1.19 1999/08/16 18:38:50 art Exp $"; +static char rcsid[] = "$OpenBSD: savecore.c,v 1.20 2000/05/31 17:09:17 millert Exp $"; #endif #endif /* not lint */ @@ -333,20 +333,22 @@ check_kmem() KREAD(kd_dump, dump_nl[X_PANICSTR].n_value, &panicstr); if (panicstr) { char c, visout[5]; + size_t vislen; cp = panic_mesg; panicloc = panicstr; - do { - KREAD(kd_dump, panicloc, &c); + for (;;) { + if (KREAD(kd_dump, panicloc, &c) != 0 || c == '\0') + break; panicloc++; vis(visout, c, VIS_SAFE|VIS_NOSLASH, 0); - if (c && cp + strlen(visout) < - &panic_mesg[sizeof(panic_mesg)]) { - strcat(cp, visout); - cp += strlen(visout); - } - } while (c && cp < &panic_mesg[sizeof(panic_mesg)]); + vislen = strlen(visout); + if (cp - panic_mesg + vislen >= sizeof(panic_mesg)) + break; + strcat(cp, visout); + cp += vislen; + } } } diff --git a/sbin/savecore/savecore_old.c b/sbin/savecore/savecore_old.c index 172856750a7..6a62358e0e9 100644 --- a/sbin/savecore/savecore_old.c +++ b/sbin/savecore/savecore_old.c @@ -1,4 +1,4 @@ -/* $OpenBSD: savecore_old.c,v 1.15 1999/07/01 15:41:59 deraadt Exp $ */ +/* $OpenBSD: savecore_old.c,v 1.16 2000/05/31 17:09:17 millert Exp $ */ /* $NetBSD: savecore_old.c,v 1.1.1.1 1996/03/16 10:25:11 leo Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) 1/2/94"; #else -static char rcsid[] = "$OpenBSD: savecore_old.c,v 1.15 1999/07/01 15:41:59 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: savecore_old.c,v 1.16 2000/05/31 17:09:17 millert Exp $"; #endif #endif /* not lint */ @@ -325,19 +325,22 @@ check_kmem() (void)fread(&panicstr, sizeof(panicstr), 1, fp); if (panicstr) { char c, visout[5]; + size_t vislen; - cp = panic_mesg; - (void)fseek(fp, dumplo + ok(panicstr), SEEK_SET); cp = panic_mesg; - do { + (void)fseek(fp, dumplo + ok(panicstr), SEEK_SET); + for (;;) { c = getc(fp); + if (c == EOF || c == '\0') + break; + vis(visout, c, VIS_SAFE|VIS_NOSLASH, 0); - if (c && cp + strlen(visout) < - &panic_mesg[sizeof(panic_mesg)]) { - strcat(cp, visout); - cp += strlen(visout); - } - } while (c && cp < &panic_mesg[sizeof(panic_mesg)]); + vislen = strlen(visout); + if (cp - panic_mesg + vislen >= sizeof(panic_mesg)) + break; + strcat(cp, visout); + cp += vislen; + } } /* Don't fclose(fp), we use dumpfd later. */ } |