Skip to content

Commit

Permalink
Add special case for KERN_PROC_PATHNAME sysctl to return correct value.
Browse files Browse the repository at this point in the history
  • Loading branch information
staceyson committed Mar 17, 2013
1 parent 94db009 commit 6a1eccb
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion work/qemu-1.4.0/bsd-user/syscall.c
Expand Up @@ -485,9 +485,12 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
abi_ulong oldlen = 0; abi_ulong oldlen = 0;
int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i; int32_t *snamep = g_malloc(sizeof(int32_t) * namelen), *p, *q, i;
uint32_t kind = 0; uint32_t kind = 0;
abi_ulong argv, argv0;
char *fullpath = NULL;


if (oldlenp) if (oldlenp)
get_user_ual(oldlen, oldlenp); if (get_user_ual(oldlen, oldlenp))
return -TARGET_EFAULT;
if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1))) if (!(hnamep = lock_user(VERIFY_READ, namep, namelen, 1)))
return -TARGET_EFAULT; return -TARGET_EFAULT;
if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1))) if (newp && !(hnewp = lock_user(VERIFY_READ, newp, newlen, 1)))
Expand Down Expand Up @@ -527,6 +530,42 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
#endif #endif
goto out; goto out;


case KERN_PROC:
switch(snamep[2]) {
case KERN_PROC_PATHNAME:
if (get_user_ual(argv, TARGET_PS_STRINGS)) {
ret = -TARGET_EFAULT;
goto out;
}
if (get_user_ual(argv0, argv)) {
ret = -TARGET_EFAULT;
goto out;
}

fullpath = realpath(g2h(argv0), NULL);
if (NULL == fullpath)
fullpath = (char *)g2h(argv0);
holdlen = strlen(fullpath) + 1;
if (holdp) {
if (oldlen < holdlen) {
ret = -TARGET_EINVAL;
goto out;
}
if (!access_ok(VERIFY_WRITE, argv0,
holdlen)) {
ret = -TARGET_EFAULT;
goto out;
}
strlcpy(holdp, fullpath, oldlen);
}
ret = 0;
goto out;

default:
break;
}
break;

default: default:
break; break;
} }
Expand Down Expand Up @@ -558,6 +597,8 @@ static abi_long do_freebsd_sysctl(abi_ulong namep, int32_t namelen, abi_ulong ol
#endif #endif


out: out:
if (fullpath)
free(fullpath);
if (oldlenp) if (oldlenp)
put_user_ual(holdlen, oldlenp); put_user_ual(holdlen, oldlenp);
unlock_user(hnamep, namep, 0); unlock_user(hnamep, namep, 0);
Expand Down

0 comments on commit 6a1eccb

Please sign in to comment.