mirror of
https://github.com/kgabis/parson.git
synced 2024-11-24 06:05:29 +00:00
Fix memleak when parsing keys with embedded null bytes (#157)
* Fix memleak when parsing key with embedded null byte This commit fixes and adds a test for a memory leak that occurs when parsing strings with keys that have a null byte embedded in them. This memory leak can be triggered with the following line, where this call returns a `NULL`: ```c json_parse_string("{\"\\u0000\"") ``` This memory leak happens in the `parse_object_value` function in here: ``` new_key = get_quoted_string(string, &key_len); <---- ALLOCATION /* We do not support key names with embedded \0 chars */ if (new_key == NULL || key_len != strlen(new_key)) { json_value_free(output_value); return NULL; <---- `new_key` NOT FREED } SKIP_WHITESPACES(string); if (**string != ':') { parson_free(new_key); json_value_free(output_value); return NULL; } ``` * Increments version to 1.1.2 Co-authored-by: Krzysztof Gabis <kgabis@gmail.com>
This commit is contained in:
parent
60b2c69f17
commit
ab7f5e5401
@ -3,7 +3,7 @@ project(parson C)
|
||||
|
||||
include (GNUInstallDirs)
|
||||
|
||||
set(PARSON_VERSION 1.1.1)
|
||||
set(PARSON_VERSION 1.1.2)
|
||||
add_library(parson parson.c)
|
||||
target_include_directories(parson PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "parson",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"repo": "kgabis/parson",
|
||||
"description": "Small json parser and reader",
|
||||
"keywords": [ "json", "parser" ],
|
||||
|
5
parson.c
5
parson.c
@ -1,7 +1,7 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Parson 1.1.1 ( http://kgabis.github.com/parson/ )
|
||||
Parson 1.1.2 ( http://kgabis.github.com/parson/ )
|
||||
Copyright (c) 2012 - 2021 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
@ -742,6 +742,9 @@ static JSON_Value * parse_object_value(const char **string, size_t nesting) {
|
||||
new_key = get_quoted_string(string, &key_len);
|
||||
/* We do not support key names with embedded \0 chars */
|
||||
if (new_key == NULL || key_len != strlen(new_key)) {
|
||||
if (new_key) {
|
||||
parson_free(new_key);
|
||||
}
|
||||
json_value_free(output_value);
|
||||
return NULL;
|
||||
}
|
||||
|
2
parson.h
2
parson.h
@ -1,7 +1,7 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
Parson 1.1.1 ( http://kgabis.github.com/parson/ )
|
||||
Parson 1.1.2 ( http://kgabis.github.com/parson/ )
|
||||
Copyright (c) 2012 - 2021 Krzysztof Gabis
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
Loading…
Reference in New Issue
Block a user