summaryrefslogtreecommitdiff
path: root/hostname.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2016-12-24 16:23:45 +0000
committerDmitry V. Levin <ldv@altlinux.org>2016-12-25 11:32:45 +0000
commit9af28a4d1313ffb1f5ef57a352ba77070b0977e1 (patch)
tree965837fb2527bc42e670cffde1a07b9c410db9b2 /hostname.c
parentbd43e0954b15ff1d904749dbc9f4ee52b56f60d8 (diff)
downloadstrace-9af28a4d1313ffb1f5ef57a352ba77070b0977e1.tar.gz
Fix decoding of sethostname syscall
The second argument of sethostname syscall is not an unsigned long but unsigned int. The kernel does not look at the string argument when the length argument is too long. * hostname.c [HAVE_LINUX_UTSNAME_H]: Include <linux/utsname.h>. [!__NEW_UTS_LEN] (__NEW_UTS_LEN): Define. (SYS_FUNC(sethostname)): Treat the second argument as unsigned int. Print the first argument as a pointer when the second argument exceeds __NEW_UTS_LEN. * tests/sethostname.c [HAVE_LINUX_UTSNAME_H]: Include <linux/utsname.h>. [!__NEW_UTS_LEN] (__NEW_UTS_LEN): Define. (main): Use it. Check that the second argument of sethostname is handled as unsigned int. Check that the first argument is printed as a pointer when the second argument exceeds __NEW_UTS_LEN.
Diffstat (limited to 'hostname.c')
-rw-r--r--hostname.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/hostname.c b/hostname.c
index cc66f3ff2..394fdf605 100644
--- a/hostname.c
+++ b/hostname.c
@@ -1,9 +1,24 @@
#include "defs.h"
+#ifdef HAVE_LINUX_UTSNAME_H
+# include <linux/utsname.h>
+#endif
+
+#ifndef __NEW_UTS_LEN
+# define __NEW_UTS_LEN 64
+#endif
+
SYS_FUNC(sethostname)
{
- printstrn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
- tprintf(", %lu", tcp->u_arg[1]);
+ unsigned int len = tcp->u_arg[1];
+
+ if (len > __NEW_UTS_LEN) {
+ printaddr(tcp->u_arg[0]);
+ } else {
+ printstrn(tcp, tcp->u_arg[0], len);
+ }
+
+ tprintf(", %u", len);
return RVAL_DECODED;
}