fix vulnerability in JSON parsing (#9491)
Timotej S committed
Jul 7, 2020 at 12:12 UTC
10e6b747dae6fa42ccfeeb7b4511e8fec31c61b2
1 file changed
+5
-3
libnetdata/json/json.c
+5
-3
@@ -137,10 +137,12 @@ int json_callback_print(JSON_ENTRY *e)
137
* @param e the output structure
138
*/
139
static inline void json_jsonc_set_string(JSON_ENTRY *e,char *key,const char *value) {
140
- size_t length = strlen(key);
140
+ size_t len = strlen(key);
141
+ if(len > JSON_NAME_LEN)
142
+ len = JSON_NAME_LEN;
143
e->type = JSON_STRING;
142
- memcpy(e->name,key,length);
143
- e->name[length] = 0x00;
144
+ memcpy(e->name,key,len);
145
+ e->name[len] = 0x00;
146
e->data.string = (char *) value;
147
}
148