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-17 23:08:12 +0200 |
commit | 71df9e17920283b8170bb65da98e279cb508e9b9 (patch) | |
tree | 0e3e8a8df04125cf7be72ea9c0bcc8362cf19a22 /ctl-lib/ctl-action.c | |
parent | 77c5fe6240f08a55f61afc8d0ed48129bd8394d2 (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 | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index e1329e2..c8df2c7 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -139,30 +139,26 @@ 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; + int i; + char *tmp; if(! uri || ! first || ! second) { return; } - tmp = strchr(uri, '#'); - first_len = strlen(uri); + tmp = strdup(uri); + *first = tmp; - if (!tmp) { - *first = calloc(1, sizeof(char) * first_len); - strcpy(*first, uri); + for(i = 0; i < strlen(uri); ++i) { + if(tmp[i] == '#') { + tmp[i] = '\0'; + *second = &tmp[++i]; + break; + } } - 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); - - strncpy(*first, uri, first_len); - strncpy(*second, tmp+1, second_len); - } + if(tmp[i] == '\0') + *second = ""; } /*** This function will fill the CtlActionT pointer given in parameters for a |