arpadboda commented on a change in pull request #674: Minificpp 1007 - ECU C2 integration. URL: https://github.com/apache/nifi-minifi-cpp/pull/674#discussion_r353269082
########## File path: nanofi/ecu/c2_client.c ########## @@ -0,0 +1,235 @@ +#ifdef __cplusplus +extern "C" { +#endif +#include <coap/c2structs.h> +#include <coap/c2protocol.h> +#include <coap/c2agent.h> +#include <c2_api/c2api.h> +#include <api/ecu.h> + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "utlist.h" +#include "uthash.h" + +typedef struct config_params { + char * key; // name of the param + char * value; // value of the param + UT_hash_handle hh; +} config_params; + +char ** parse_line(char * line, size_t len) { + char * tok = strtok(line, " ="); + char ** tokens = (char **)malloc(sizeof(char *) * 2); + int i = 0; + while (tok) { + if (i > 2) break; + size_t s = strlen(tok); + char * token = (char *)malloc(sizeof(char) * (s + 1)); + memset(token, 0, (s + 1)); + strcpy(token, tok); + tokens[i++] = token; + tok = strtok(NULL, " =\n"); + } + return tokens; Review comment: This function seems to be wrong in multiple ways: - The parameter called "len" is completely unused. - It's called parse_line, actually it acts as a string tokeniser, but stop tokenising at 3 tokens. - Even though it stops tokenising at 3 tokens (i can be 0, 1 or 2), it only allocates memory for 2, so it's going to segfault. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services