aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-11-18 23:07:38 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-11-21 13:29:02 +0000
commitebd3cddb4c75b284b0d3345ab81980f8f4b44b62 (patch)
treeb69acdd4353b734c324f797fb5c89419fb1f1f4e
parentfe1ed39846c6537ebfe19d22500ee2e38587c143 (diff)
osmo_strlcpy: sanitize: don't memcpy from NULL src even if len is 0
Some callers pass NULL and len == 0. The semantics are that we then nul-terminate an emtpy string. Avoid a sanitizer warning by not calling memcpy() for the NULL case. Change-Id: I883048cf2807e606c6481634dbd569fc12aed889
-rw-r--r--src/utils.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/utils.c b/src/utils.c
index f63ff891..bc5329d8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -385,7 +385,8 @@ size_t osmo_strlcpy(char *dst, const char *src, size_t siz)
if (siz) {
size_t len = (ret >= siz) ? siz - 1 : ret;
- memcpy(dst, src, len);
+ if (src)
+ memcpy(dst, src, len);
dst[len] = '\0';
}
return ret;