From: Dmitry V. Levin Date: Sat, 6 Jan 2018 01:45:16 +0000 (+0000) Subject: desc.c: use xsnprintf instead of sprintf X-Git-Tag: v4.21~199 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9175ac5ce84931d5c78c8e4f2163a93256d7f94;p=strace desc.c: use xsnprintf instead of sprintf * desc.c: Include "xstring.h". (decode_select): Replace sprintf with xsnprintf. --- 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';