summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2022-08-09 08:00:00 +0000
committerEugene Syromyatnikov <evgsyr@gmail.com>2022-08-11 14:34:17 +0200
commit76af385a04f398ada97ef4d2b555045cba443da8 (patch)
tree77fc3a326d8681ae554c2a149e404dbbead8a22f
parentc6aa96b4ef83337df078667eef5af725501d1d94 (diff)
downloadstrace-76af385a04f398ada97ef4d2b555045cba443da8.tar.gz
net: print the data returned by SO_ERROR as a string if it is too short
The data returned by getsockopt SO_ERROR is an integer. If the buffer size specified by userspace is less than sizeof(int), the data written by the kernel should not be interpreted as an integer. * src/net.c (print_get_error): Print the buffer as a string if its length is less than sizeof(int).
-rw-r--r--src/net.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/net.c b/src/net.c
index a6ff1d653..4a499cd72 100644
--- a/src/net.c
+++ b/src/net.c
@@ -691,14 +691,16 @@ print_get_ucred(struct tcb *const tcp, const kernel_ulong_t addr,
static void
print_get_error(struct tcb *const tcp, const kernel_ulong_t addr,
- unsigned int len)
+ const unsigned int len)
{
unsigned int err;
- if (len > sizeof(err))
- len = sizeof(err);
+ if (len < sizeof(err)) {
+ printstrn(tcp, addr, len);
+ return;
+ }
- if (umoven_or_printaddr(tcp, addr, len, &err))
+ if (umove_or_printaddr(tcp, addr, &err))
return;
tprint_indirect_begin();