From cf3c9191510735699da14bb5a680f6af9b8a8dcf Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 17 May 2018 00:26:01 +0200 Subject: Good usage of strncat and strncpy This change ensure that there are no write over the destination buffer size Change-Id: Ic213e70fab83dfae39a8ff030c823a6ce68aab64 Signed-off-by: Romain Forlot --- ctl-lib/ctl-action.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'ctl-lib/ctl-action.c') diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index e1329e2..f25e137 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -139,29 +139,28 @@ static void ActionDynRequest(AFB_ReqT request) { void ParseURI(const char *uri, char **first, char **second) { - size_t first_len = 0, second_len = 0; - const char *tmp; + char *tmp; if(! uri || ! first || ! second) { return; } - tmp = strchr(uri, '#'); - first_len = strlen(uri); - + tmp = strdup(uri); if (!tmp) { - *first = calloc(1, sizeof(char) * first_len); - strcpy(*first, uri); + *first = NULL; + *second = NULL; + return; } - else { - second_len = strlen(tmp); - first_len = first_len - second_len; - *first = calloc(1, sizeof(char) * first_len); - *second = calloc(1, sizeof(char) * second_len); + *first = tmp; - strncpy(*first, uri, first_len); - strncpy(*second, tmp+1, second_len); + tmp = strchrnul(tmp, '#'); + if(tmp[0] == '\0') { + *second = NULL; + } + else { + tmp[0] = '\0'; + *second = &tmp[1]; } } -- cgit 1.2.3-korg