src: _snprintf() helper functions nul-terminate buffers, if possible
This patch inconditionally initializes the buffer we get to nul-terminate it, whenever possible. It's a very simple solution to catch three overly corner cases: 1) snprintf() returns -1, very much unlikely in practise. 2) msg->len == 0: In such case, I would expect this function is never called with an empty message, but let's be safe in this case too. 3) If your buffer is empty, it doesn't nul-terminate the buffer. Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
This commit is contained in:
parent
14af167a55
commit
5994198208
|
@ -902,6 +902,9 @@ int osmux_snprintf(char *buf, size_t size, struct msgb *msg)
|
|||
int msg_len = msg->len;
|
||||
int ret;
|
||||
|
||||
if (size)
|
||||
buf[0] = '\0';
|
||||
|
||||
while (msg_len > 0) {
|
||||
if (msg_len < sizeof(struct osmux_hdr)) {
|
||||
LOGP(DLMIB, LOGL_ERROR,
|
||||
|
|
Loading…
Reference in New Issue