summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_linker.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-09-12 00:50:23 +0000
committerpeter <peter@FreeBSD.org>2001-09-12 00:50:23 +0000
commit1df17fc5a33d213a43c26a3a57477550abccd81c (patch)
treeeb86bfc0b4bbeb9195d7e504d120cd93c01c4225 /sys/kern/kern_linker.c
parent03950a46f77126a038cc19570190aca5c32a06cf (diff)
downloadFreeBSD-src-1df17fc5a33d213a43c26a3a57477550abccd81c.zip
FreeBSD-src-1df17fc5a33d213a43c26a3a57477550abccd81c.tar.gz
Fix the kern.module_path issue that required the trailing '/' character
on each module path component. Fix a one-byte buffer overflow at the same time that got highlighted in the process.
Diffstat (limited to 'sys/kern/kern_linker.c')
-rw-r--r--sys/kern/kern_linker.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c
index 97d8a9a..bf6face 100644
--- a/sys/kern/kern_linker.c
+++ b/sys/kern/kern_linker.c
@@ -1286,7 +1286,7 @@ SYSINIT(preload, SI_SUB_KLD, SI_ORDER_MIDDLE, linker_preload, 0);
*/
static char linker_hintfile[] = "linker.hints";
-static char linker_path[MAXPATHLEN] = "/boot/kernel;/boot/modules/;/modules/";
+static char linker_path[MAXPATHLEN] = "/boot/kernel;/boot/modules;/modules";
SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path,
sizeof(linker_path), "module load search path");
@@ -1310,8 +1310,8 @@ linker_lookup_file(const char *path, int pathlen,
{
struct nameidata nd;
struct proc *p = curproc; /* XXX */
- char *result, **cpp;
- int error, len, extlen, flags;
+ char *result, **cpp, *sep;
+ int error, len, extlen, reclen, flags;
enum vtype type;
extlen = 0;
@@ -1321,12 +1321,13 @@ linker_lookup_file(const char *path, int pathlen,
extlen = len;
}
extlen++; /* trailing '\0' */
+ sep = (path[pathlen - 1] != '/') ? "/" : "";
- result = malloc((pathlen + namelen + extlen), M_LINKER, M_WAITOK);
+ reclen = pathlen + strlen(sep) + namelen + extlen + 1;
+ result = malloc(reclen, M_LINKER, M_WAITOK);
for (cpp = linker_ext_list; *cpp; cpp++) {
- bcopy(path, result, pathlen);
- bcopy(name, result + pathlen, namelen);
- strcpy(result + namelen + pathlen, *cpp);
+ snprintf(result, reclen, "%.*s%s%.*s%s", pathlen, path, sep,
+ namelen, name, *cpp);
/*
* Attempt to open the file, and return the path if we succeed
* and it's a regular file.
@@ -1367,16 +1368,17 @@ linker_hints_lookup(const char *path, int pathlen,
struct nameidata nd;
struct vattr vattr, mattr;
u_char *hints = NULL;
- u_char *cp, *recptr, *bufend, *result, *best, *pathbuf;
+ u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep;
int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
result = NULL;
bestver = found = 0;
- reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen;
+ sep = (path[pathlen - 1] != '/') ? "/" : "";
+ reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen +
+ strlen(sep) + 1;
pathbuf = malloc(reclen, M_LINKER, M_WAITOK);
- bcopy(path, pathbuf, pathlen);
- strcpy(pathbuf + pathlen, linker_hintfile);
+ snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep, linker_hintfile);
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, p);
flags = FREAD;
@@ -1463,7 +1465,8 @@ linker_hints_lookup(const char *path, int pathlen,
/*
* KLD is newer than hints file. What we should do now ?
*/
- printf("warning: KLD '%s' is newer than the linker.hints file\n", result);
+ printf("warning: KLD '%s' is newer than the linker.hints file\n",
+ result);
}
bad:
if (hints)
OpenPOWER on IntegriCloud