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
This commit is contained in:
Marius Strobl 2005-10-25 12:49:56 +00:00
parent a92cb60b4e
commit 79aae78c89
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=151649

View File

@ -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;