From d9dd1d3cf51a248dc7c04624a21e5dd9eba02421 Mon Sep 17 00:00:00 2001 From: Nikita Kalyazin Date: Mon, 2 Dec 2013 09:00:15 +0400 Subject: [PATCH] [FIX] pack_string: correct null string handling Change-Id: Ic3d7ea27c78b820625958148e473da810efa2d2e Signed-off-by: Nikita Kalyazin --- include/binproto.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/binproto.h b/include/binproto.h index 28631e1..1e90042 100644 --- a/include/binproto.h +++ b/include/binproto.h @@ -90,9 +90,14 @@ static inline char *pack_int64(char *to, uint64_t val) static char __attribute__((used)) *pack_string(char *to, const char *str) { - size_t len = strlen(str) + 1; - strncpy(to, str, len); - return to + len; + if (!str) { + *to = '\0'; + return to + 1; + } else { + size_t len = strlen(str) + 1; + strncpy(to, str, len); + return to + len; + } } static char __attribute__((used)) *pack_bin(char *to, const char *from, -- 2.7.4