From d9175ac5ce84931d5c78c8e4f2163a93256d7f94 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Sat, 6 Jan 2018 01:45:16 +0000 Subject: [PATCH] desc.c: use xsnprintf instead of sprintf * desc.c: Include "xstring.h". (decode_select): Replace sprintf with xsnprintf. --- desc.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/desc.c b/desc.c index 52e58c86..e0b2dcd9 100644 --- a/desc.c +++ b/desc.c @@ -30,6 +30,7 @@ */ #include "defs.h" +#include "xstring.h" SYS_FUNC(close) { @@ -157,7 +158,9 @@ decode_select(struct tcb *const tcp, const kernel_ulong_t *const args, /* +2 chars needed at the end: ']',NUL */ if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { if (first) { - outptr += sprintf(outptr, "%s%s [%u", + outptr += xsnprintf(outptr, + sizeof(outstr) - (outptr - outstr), + "%s%s [%u", sep, i == 0 ? "in" : i == 1 ? "out" : "except", j @@ -165,7 +168,9 @@ decode_select(struct tcb *const tcp, const kernel_ulong_t *const args, first = 0; sep = ", "; } else { - outptr += sprintf(outptr, " %u", j); + outptr += xsnprintf(outptr, + sizeof(outstr) - (outptr - outstr), + " %u", j); } } if (--ready_fds == 0) @@ -179,7 +184,9 @@ decode_select(struct tcb *const tcp, const kernel_ulong_t *const args, if (args[4]) { const char *str = sprint_tv_ts(tcp, args[4]); if (outptr + sizeof("left ") + strlen(sep) + strlen(str) < end_outstr) { - outptr += sprintf(outptr, "%sleft %s", sep, str); + outptr += xsnprintf(outptr, + sizeof(outstr) - (outptr - outstr), + "%sleft %s", sep, str); } } *outptr = '\0'; -- 2.40.0