Avoid reading outside of allocated memory

on command execution if the output is empty.
This commit is contained in:
itohy 1998-11-01 03:01:53 +00:00
parent 1cfb41e0d6
commit f748b52ef3
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.43 1998/10/13 17:08:34 wsanchez Exp $ */ /* $NetBSD: main.c,v 1.44 1998/11/01 03:01:53 itohy Exp $ */
/* /*
* Copyright (c) 1988, 1989, 1990, 1993 * Copyright (c) 1988, 1989, 1990, 1993
@ -39,7 +39,7 @@
*/ */
#ifdef MAKE_BOOTSTRAP #ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: main.c,v 1.43 1998/10/13 17:08:34 wsanchez Exp $"; static char rcsid[] = "$NetBSD: main.c,v 1.44 1998/11/01 03:01:53 itohy Exp $";
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
@ -51,7 +51,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993\n\
#if 0 #if 0
static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94"; static char sccsid[] = "@(#)main.c 8.3 (Berkeley) 3/19/94";
#else #else
__RCSID("$NetBSD: main.c,v 1.43 1998/10/13 17:08:34 wsanchez Exp $"); __RCSID("$NetBSD: main.c,v 1.44 1998/11/01 03:01:53 itohy Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#endif #endif
@ -1012,9 +1012,9 @@ Cmd_Exec(cmd, err)
* install it in the variable. * install it in the variable.
*/ */
res[cc] = '\0'; res[cc] = '\0';
cp = &res[cc] - 1; cp = &res[cc];
if (*cp == '\n') { if (cc > 0 && *--cp == '\n') {
/* /*
* A final newline is just stripped * A final newline is just stripped
*/ */