X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Futils%2Fproto.c;h=f767fa21a887fdd929a32ea45f16fec656ff6b5f;hp=beaa07e98397f18876f27952ab38ed83ff673638;hb=f1357b416c1264501958292c13c38ef8b5dece92;hpb=147e814d602f90e411a948613e85e627f5858018 diff --git a/src/utils/proto.c b/src/utils/proto.c index beaa07e..f767fa2 100644 --- a/src/utils/proto.c +++ b/src/utils/proto.c @@ -91,7 +91,7 @@ static ssize_t marshal_binary(char *buf, size_t buf_len, size_t len, const unsigned char *v) { uint32_t tmp = htonl((uint32_t)len); - if (buf_len >= len) { + if (buf_len >= sizeof(tmp) + len) { memcpy(buf, &tmp, sizeof(tmp)); memcpy(buf + sizeof(tmp), v, len); } @@ -102,8 +102,10 @@ static ssize_t marshal_string(char *buf, size_t buf_len, const char *v) { /* The actual string including the terminating null byte. */ - return marshal_binary(buf, buf_len, - strlen(v) + 1, (const unsigned char *)v); + size_t len = strlen(v) + 1; + if (buf_len >= len) + memcpy(buf, v, len); + return len; } /* marshal_string */ /*