From 79aae78c8906b05a9d08bc17739230e2d483205b Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Tue, 25 Oct 2005 12:49:56 +0000 Subject: [PATCH] In ofw_parsedev() check the return value of malloc() and protect against a NULL pointer dereference when ofw_parsedev() is called with a NULL path argument. Tested on: powerpc (grehan), sparc64 --- sys/boot/ofw/libofw/devicename.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sys/boot/ofw/libofw/devicename.c b/sys/boot/ofw/libofw/devicename.c index a2c48975417a..3cae23ce2024 100644 --- a/sys/boot/ofw/libofw/devicename.c +++ b/sys/boot/ofw/libofw/devicename.c @@ -99,9 +99,13 @@ ofw_parsedev(struct ofw_devdesc **dev, const char *devspec, const char **path) return(ENOENT); found: - if (*s != '\0') + if (path != NULL && *s != '\0') *path = s; idev = malloc(sizeof(struct ofw_devdesc)); + if (idev == NULL) { + printf("ofw_parsedev: malloc failed\n"); + return ENOMEM; + } strcpy(idev->d_path, name); idev->d_dev = dv; idev->d_type = dv->dv_type;