Skip to content

Commit

Permalink
linux-user: Don't write off end of new_utsname buffer
Browse files Browse the repository at this point in the history
Use g_strlcpy() rather than strcpy() to copy the uname string
into the structure we return to the guest for the uname syscall.
This avoids overrunning the buffer if the user passed us an
overlong string via the QEMU command line.

We fix a comment typo while we're in the neighbourhood.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
  • Loading branch information
pm215 authored and Riku Voipio committed Aug 4, 2016
1 parent ba4b3f6 commit 332c978
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions linux-user/syscall.c
Expand Up @@ -9237,12 +9237,14 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
goto efault;
ret = get_errno(sys_uname(buf));
if (!is_error(ret)) {
/* Overrite the native machine name with whatever is being
/* Overwrite the native machine name with whatever is being
emulated. */
strcpy (buf->machine, cpu_to_uname_machine(cpu_env));
/* Allow the user to override the reported release. */
if (qemu_uname_release && *qemu_uname_release)
strcpy (buf->release, qemu_uname_release);
if (qemu_uname_release && *qemu_uname_release) {
g_strlcpy(buf->release, qemu_uname_release,
sizeof(buf->release));
}
}
unlock_user_struct(buf, arg1, 1);
}
Expand Down

0 comments on commit 332c978

Please sign in to comment.