diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-05-17 00:26:01 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-05-18 13:52:47 +0000 |
commit | a68eba948a30885e87f12690ce5d4210629c1e30 (patch) | |
tree | 8b282b69404979c570b28d5afa164f6c99e5b44c /ctl-lib/ctl-action.c | |
parent | 2acfbf23831472f8a9d61917b1627c5008a63ee2 (diff) |
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-action.c')
-rw-r--r-- | ctl-lib/ctl-action.c | 27 |
1 files changed, 13 insertions, 14 deletions
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]; } } |