Indeed, instead of hiding the kern___getcwd() bug by bogus cast

in r276564, change path type to char * (pathnames are always char *).
And remove bogus casts of malloc().
kern___getcwd() internally doesn't actually use or support u_char *
paths, except to copy them to a normal char * path.

These changes are not visible to libc as libc/gen/getcwd.c misdeclares
__getcwd() as taking a plain char * path.

While here remove _SYS_SYSPROTO_H_ for __getcwd() syscall as
we always have sysproto.h.

Pointed out by:	bde

MFC after:	1 week
This commit is contained in:
Dmitry Chagin 2015-01-04 10:34:02 +00:00
parent 41ddc6ea3d
commit 9f7a06f27e
5 changed files with 8 additions and 16 deletions

View File

@ -583,7 +583,7 @@
323 AUE_NULL OBSOL thr_wakeup 323 AUE_NULL OBSOL thr_wakeup
324 AUE_MLOCKALL NOPROTO { int mlockall(int how); } 324 AUE_MLOCKALL NOPROTO { int mlockall(int how); }
325 AUE_MUNLOCKALL NOPROTO { int munlockall(void); } 325 AUE_MUNLOCKALL NOPROTO { int munlockall(void); }
326 AUE_GETCWD NOPROTO { int __getcwd(u_char *buf, u_int buflen); } 326 AUE_GETCWD NOPROTO { int __getcwd(char *buf, u_int buflen); }
327 AUE_NULL NOPROTO { int sched_setparam (pid_t pid, \ 327 AUE_NULL NOPROTO { int sched_setparam (pid_t pid, \
const struct sched_param *param); } const struct sched_param *param); }

View File

@ -186,7 +186,7 @@ linux_getcwd_scandir(lvpp, uvpp, bpp, bufp, td)
dirbuflen = DIRBLKSIZ; dirbuflen = DIRBLKSIZ;
if (dirbuflen < va.va_blocksize) if (dirbuflen < va.va_blocksize)
dirbuflen = va.va_blocksize; dirbuflen = va.va_blocksize;
dirbuf = (char *)malloc(dirbuflen, M_TEMP, M_WAITOK); dirbuf = malloc(dirbuflen, M_TEMP, M_WAITOK);
#if 0 #if 0
unionread: unionread:
@ -413,7 +413,7 @@ linux_getcwd_common (lvp, rvp, bpp, bufp, limit, flags, td)
int int
linux_getcwd(struct thread *td, struct linux_getcwd_args *args) linux_getcwd(struct thread *td, struct linux_getcwd_args *args)
{ {
caddr_t bp, bend, path; char *bp, *bend, *path;
int error, len, lenused; int error, len, lenused;
#ifdef DEBUG #ifdef DEBUG
@ -428,9 +428,9 @@ linux_getcwd(struct thread *td, struct linux_getcwd_args *args)
else if (len < 2) else if (len < 2)
return ERANGE; return ERANGE;
path = (char *)malloc(len, M_TEMP, M_WAITOK); path = malloc(len, M_TEMP, M_WAITOK);
error = kern___getcwd(td, (u_char *)path, UIO_SYSSPACE, len); error = kern___getcwd(td, path, UIO_SYSSPACE, len);
if (!error) { if (!error) {
lenused = strlen(path) + 1; lenused = strlen(path) + 1;
if (lenused <= args->bufsize) { if (lenused <= args->bufsize) {

View File

@ -571,7 +571,7 @@
323 AUE_NULL OBSOL thr_wakeup 323 AUE_NULL OBSOL thr_wakeup
324 AUE_MLOCKALL STD { int mlockall(int how); } 324 AUE_MLOCKALL STD { int mlockall(int how); }
325 AUE_MUNLOCKALL STD { int munlockall(void); } 325 AUE_MUNLOCKALL STD { int munlockall(void); }
326 AUE_GETCWD STD { int __getcwd(u_char *buf, u_int buflen); } 326 AUE_GETCWD STD { int __getcwd(char *buf, u_int buflen); }
327 AUE_NULL STD { int sched_setparam (pid_t pid, \ 327 AUE_NULL STD { int sched_setparam (pid_t pid, \
const struct sched_param *param); } const struct sched_param *param); }

View File

@ -1043,14 +1043,6 @@ vfs_cache_lookup(ap)
return (error); return (error);
} }
#ifndef _SYS_SYSPROTO_H_
struct __getcwd_args {
u_char *buf;
u_int buflen;
};
#endif
/* /*
* XXX All of these sysctls would probably be more productive dead. * XXX All of these sysctls would probably be more productive dead.
*/ */
@ -1069,7 +1061,7 @@ sys___getcwd(td, uap)
} }
int int
kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen) kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, u_int buflen)
{ {
char *bp, *tmpbuf; char *bp, *tmpbuf;
struct filedesc *fdp; struct filedesc *fdp;

View File

@ -57,7 +57,7 @@ struct stat;
struct thr_param; struct thr_param;
struct __wrusage; struct __wrusage;
int kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, int kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg,
u_int buflen); u_int buflen);
int kern_accept(struct thread *td, int s, struct sockaddr **name, int kern_accept(struct thread *td, int s, struct sockaddr **name,
socklen_t *namelen, struct file **fp); socklen_t *namelen, struct file **fp);