aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-action.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-05-17 00:26:01 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:54 +0100
commitcf3c9191510735699da14bb5a680f6af9b8a8dcf (patch)
tree8b282b69404979c570b28d5afa164f6c99e5b44c /ctl-lib/ctl-action.c
parentde2f6f5dc95ab9254d9015c263590ec2d24cdef7 (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.c27
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];
}
}