summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordbiastoch <dbiastoch@de.adit-jv.com>2021-03-02 15:30:12 +0100
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2021-06-30 10:54:59 +0900
commit72dc5bb1fa7bd0823ef17269ab6e5c7dd76f90fd (patch)
tree631ae247e49d032b4606343074a0df45867757d1
parentec6dbfceb71bf11c944fa061064a7625e0240ef3 (diff)
downloadDLT-daemon-72dc5bb1fa7bd0823ef17269ab6e5c7dd76f90fd.tar.gz
dlt-receive:Fix compiler warning
dlt_common.c: -Check if filter file fits into read buffer -Cast 'filename' into non-const to make it json-c API conform Signed-off-by: dbiastoch <dbiastoch@de.adit-jv.com>
-rw-r--r--include/dlt/dlt_common.h1
-rw-r--r--src/shared/dlt_common.c12
2 files changed, 9 insertions, 4 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index 89f9c96..f2ffe50 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -298,6 +298,7 @@ enum {
# define DLT_FILTER_MAX 30 /**< Maximum number of filters */
# define JSON_FILTER_NAME_SIZE 16 /* Size of buffer for the filter names in json filter files */
+# define JSON_FILTER_SIZE 200 /* Size in bytes, that the definition of one filter with all parameters needs */
# define DLT_MSG_READ_VALUE(dst, src, length, type) \
{ \
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index f07e906..a210e5e 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -475,8 +475,7 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int
return DLT_RETURN_WRONG_PARAMETER;
FILE *handle;
- char buffer[1024];
- long file_size;
+ char buffer[JSON_FILTER_SIZE*DLT_FILTER_MAX];
struct json_object *j_parsed_json;
struct json_object *j_app_id;
struct json_object *j_context_id;
@@ -500,7 +499,12 @@ DltReturnValue dlt_json_filter_load(DltFilter *filter, const char *filename, int
return DLT_RETURN_ERROR;
}
- fread(buffer, sizeof(buffer), 1, handle);
+ if (fread(buffer, sizeof(buffer), 1, handle) != 0) {
+ if (!feof(handle)) {
+ dlt_vlog(LOG_WARNING, "Filter file %s is to big for reading it with current buffer!\n", filename);
+ return DLT_RETURN_ERROR;
+ }
+ }
j_parsed_json = json_tokener_parse_verbose(buffer, &jerr);
@@ -731,7 +735,7 @@ DltReturnValue dlt_json_filter_save(DltFilter *filter, const char *filename, int
}
printf("Saving current filter into '%s'\n", filename);
- json_object_to_file(filename, json_filter_obj);
+ json_object_to_file((char*)filename, json_filter_obj);
return DLT_RETURN_OK;
}