summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-07-15 16:07:23 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-07-15 16:07:23 +0200
commit128d9e23436584ea0d52c281b8fecb3b10f7953a (patch)
tree15b6dc936c08a1e3e5156ab9b9036f74e22906da /src/utils.c
parent96ba20cb44e602abb292b53c9e4f92aa59998df1 (diff)
osmo_hexdump: Fix segfault when input is too long.
In snprinftf the size is a size_t (unsigned) in case we want to write more than we have available, len_remain will be < 0. This was spotted while removing hexdump from simtrace and comparing it to our implementation. int snprintf(char *str, size_t size, const char *format, ...);
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 3ee14abd..e1d4c893 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -86,6 +86,8 @@ static char *_osmo_hexdump(const unsigned char *buf, int len, char *delim)
hexd_buff[0] = 0;
for (i = 0; i < len; i++) {
int len_remain = sizeof(hexd_buff) - (cur - hexd_buff);
+ if (len_remain <= 0)
+ break;
int rc = snprintf(cur, len_remain, "%02x%s", buf[i], delim);
if (rc <= 0)
break;