Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/common Make the usage consistant and document it:
details: https://anonhg.NetBSD.org/src/rev/e19fb6a5e366
branches: trunk
changeset: 472316:e19fb6a5e366
user: christos <christos%NetBSD.org@localhost>
date: Tue Apr 27 11:36:47 1999 +0000
description:
Make the usage consistant and document it:
if the path was given in a user buffer, return the new path in
a user buffer.
if the path was given in a kernel buffer, allocate a new kernel buffer
to return the new path; the caller is responsible for freeing the buffer
if we fail always set the new path to NULL.
This usage broke when I adde the /../ shortcut. Noted by cgd.
diffstat:
sys/compat/common/compat_util.c | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)
diffs (84 lines):
diff -r 93505327f859 -r e19fb6a5e366 sys/compat/common/compat_util.c
--- a/sys/compat/common/compat_util.c Tue Apr 27 08:07:26 1999 +0000
+++ b/sys/compat/common/compat_util.c Tue Apr 27 11:36:47 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_util.c,v 1.12 1999/04/24 02:56:06 cgd Exp $ */
+/* $NetBSD: compat_util.c,v 1.13 1999/04/27 11:36:47 christos Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -62,6 +62,13 @@
* If cflag is set, we check if an attempt can be made to create
* the named file, i.e. we check if the directory it should
* be in exists.
+ *
+ * In case of success, emul_find returns 0:
+ * If sgp is provided, the path is in user space, and pbuf gets
+ * allocated in user space (in the stackgap). Otherwise the path
+ * is already in kernel space and a kernel buffer gets allocated
+ * and returned in pbuf, that must be freed by the user.
+ * In case of error, the error number is returned and *pbuf = NULL.
*/
int
emul_find(p, sgp, prefix, path, pbuf, cflag)
@@ -81,7 +88,7 @@
const char *pr;
size_t sz, len;
- buf = (char *) malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
+ buf = (char *)malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
*pbuf = path;
for (ptr = buf, pr = prefix; (*ptr = *pr) != '\0'; ptr++, pr++)
@@ -111,8 +118,10 @@
* by /../ we kill the alternate search
*/
if (ptr[1] == '.' && ptr[2] == '.' && ptr[3] == '/') {
- *pbuf = &path[3];
- goto bad;
+ len -= 3;
+ (void)memcpy(buf, &ptr[3], len);
+ ptr = buf;
+ goto good;
}
/*
@@ -167,19 +176,24 @@
goto bad3;
}
}
+
+ vrele(nd.ni_vp);
+ if (!cflag)
+ vrele(ndroot.ni_vp);
+
+good:
if (sgp == NULL)
*pbuf = buf;
else {
sz = &ptr[len] - buf;
*pbuf = stackgap_alloc(sgp, sz + 1);
- error = copyout(buf, (void *)*pbuf, sz);
+ if ((error = copyout(buf, (void *)*pbuf, sz)) != 0) {
+ *pbuf = NULL;
+ return error;
+ }
free(buf, M_TEMP);
}
-
- vrele(nd.ni_vp);
- if (!cflag)
- vrele(ndroot.ni_vp);
- return error;
+ return 0;
bad3:
vrele(ndroot.ni_vp);
@@ -187,6 +201,7 @@
vrele(nd.ni_vp);
bad:
free(buf, M_TEMP);
+ *pbuf = NULL;
return error;
}
Home |
Main Index |
Thread Index |
Old Index