summaryrefslogtreecommitdiff
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 10:11:01 -0300
commit1ebc5c3ee814650e6be7603736bdbb60d8b84fef (patch)
treea5cff1d3c4e5e4f66ac9ce67383861ce2aa86af8
parent096f389e60d0a809c2414c9dcd3adbf5c0dd51cf (diff)
evil_string: fix strndup() for non-NULL terminated strings.devs/barbieri/efl_net_socket_windows2
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.
-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 634565b77a..4534b72437 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