svn commit: r347553 - head/stand/common
Toomas Soome
tsoome at FreeBSD.org
Mon May 13 22:17:12 UTC 2019
Author: tsoome
Date: Mon May 13 22:17:11 2019
New Revision: 347553
URL: https://svnweb.freebsd.org/changeset/base/347553
Log:
loader: fix memory handling errors in module.c
file_loadraw():
check for file_alloc() and strdup() results.
we leak 'name'.
mod_load() does leak 'filename'.
mod_loadkld() does not need to check fp, file_discard() does check.
Modified:
head/stand/common/module.c
Modified: head/stand/common/module.c
==============================================================================
--- head/stand/common/module.c Mon May 13 20:57:21 2019 (r347552)
+++ head/stand/common/module.c Mon May 13 22:17:11 2019 (r347553)
@@ -499,7 +499,14 @@ file_loadraw(const char *fname, char *type, int insert
/* Looks OK so far; create & populate control structure */
fp = file_alloc();
- fp->f_name = strdup(name);
+ if (fp == NULL) {
+ snprintf(command_errbuf, sizeof (command_errbuf),
+ "no memory to load %s", name);
+ free(name);
+ close(fd);
+ return (NULL);
+ }
+ fp->f_name = name;
fp->f_type = strdup(type);
fp->f_args = NULL;
fp->f_metadata = NULL;
@@ -507,6 +514,13 @@ file_loadraw(const char *fname, char *type, int insert
fp->f_addr = loadaddr;
fp->f_size = laddr - loadaddr;
+ if (fp->f_type == NULL) {
+ snprintf(command_errbuf, sizeof (command_errbuf),
+ "no memory to load %s", name);
+ free(name);
+ close(fd);
+ return (NULL);
+ }
/* recognise space consumption */
loadaddr = laddr;
@@ -552,6 +566,7 @@ mod_load(char *modname, struct mod_depend *verinfo, in
return (ENOENT);
}
err = mod_loadkld(filename, argc, argv);
+ free(filename);
return (err);
}
@@ -607,7 +622,7 @@ mod_loadkld(const char *kldname, int argc, char *argv[
snprintf(command_errbuf, sizeof(command_errbuf),
"don't know how to load module '%s'", filename);
}
- if (err && fp)
+ if (err)
file_discard(fp);
free(filename);
return (err);
More information about the svn-src-all
mailing list