From cebedc34981fc20851ec92c818884c42aec0d8ed Mon Sep 17 00:00:00 2001 From: cperciva Date: Mon, 4 Aug 2008 07:01:42 +0000 Subject: [PATCH] Dereferencing uninitialized pointers considered harmful. Prior to this commit, calling i386_parsedev(..., X, ...) where X is "ad", "bge", or any other disk or network device name without a unit number, would result in dereferencing whatever happened to be on the stack where the variable "cp" is stored. Found by: LLVM/Clang Static Checker --- sys/boot/i386/libi386/devicename.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sys/boot/i386/libi386/devicename.c b/sys/boot/i386/libi386/devicename.c index 520fdb5eabf7..e1035aa33d05 100644 --- a/sys/boot/i386/libi386/devicename.c +++ b/sys/boot/i386/libi386/devicename.c @@ -150,6 +150,8 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path) cp++; } } + } else { + cp = np; } if (*cp && (*cp != ':')) { err = EINVAL; @@ -173,6 +175,8 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path) err = EUNIT; goto fail; } + } else { + cp = np; } if (*cp && (*cp != ':')) { err = EINVAL;