summaryrefslogtreecommitdiff
path: root/src/lib/evil
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-03-29 10:11:01 -0300
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2017-03-29 12:44:19 -0300
commit13cd93f729bd2be8b5ab84d4a1706c365acc7cb3 (patch)
tree0972c858d2a092b4559f7002cc645b9dbc83a0cd /src/lib/evil
parent9486225744efdc9a68813f0d34f4e38e04387567 (diff)
evil_string: fix strndup() for non-NULL terminated strings.
If the given string is not null-terminated, then strlen() will go out of boundaries, we must limit the lookup to given 'n' parameter. To do so use strnlen(), that is a strlen() bounded by a maximum size.
Diffstat (limited to 'src/lib/evil')
-rw-r--r--src/lib/evil/evil_string.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
index 634565b..4534b72 100644
--- a/src/lib/evil/evil_string.c
+++ b/src/lib/evil/evil_string.c
@@ -18,10 +18,9 @@
18char * 18char *
19strndup(const char *str, size_t n) 19strndup(const char *str, size_t n)
20{ 20{
21 size_t slen = strlen(str); 21 size_t slen = strnlen(str, n);
22 char *ret; 22 char *ret;
23 23
24 if (slen > n) slen = n;
25 ret = malloc (slen + 1); 24 ret = malloc (slen + 1);
26 if (!ret) return NULL; 25 if (!ret) return NULL;
27 26