mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Supports the yajl version 2
Initially the code was made to support the yajl version 1. The version 2 is now the default option in most of Linux distributions.
This commit is contained in:
parent
8d4c3e4f5c
commit
09ced44ffa
@ -70,7 +70,7 @@ int json_add_argument(modsec_rec *msr, const char *value, unsigned length)
|
|||||||
* Callback for hash key values; we use those to define the variable names
|
* Callback for hash key values; we use those to define the variable names
|
||||||
* under ARGS. Whenever we reach a new key, we update the current key value.
|
* under ARGS. Whenever we reach a new key, we update the current key value.
|
||||||
*/
|
*/
|
||||||
static int yajl_map_key(void *ctx, const unsigned char *key, unsigned int length)
|
static int yajl_map_key(void *ctx, const unsigned char *key, size_t length)
|
||||||
{
|
{
|
||||||
modsec_rec *msr = (modsec_rec *) ctx;
|
modsec_rec *msr = (modsec_rec *) ctx;
|
||||||
unsigned char *safe_key = (unsigned char *) NULL;
|
unsigned char *safe_key = (unsigned char *) NULL;
|
||||||
@ -126,7 +126,7 @@ static int yajl_boolean(void *ctx, int value)
|
|||||||
/**
|
/**
|
||||||
* Callback for string values
|
* Callback for string values
|
||||||
*/
|
*/
|
||||||
static int yajl_string(void *ctx, const unsigned char *value, unsigned int length)
|
static int yajl_string(void *ctx, const unsigned char *value, size_t length)
|
||||||
{
|
{
|
||||||
modsec_rec *msr = (modsec_rec *) ctx;
|
modsec_rec *msr = (modsec_rec *) ctx;
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ static int yajl_string(void *ctx, const unsigned char *value, unsigned int lengt
|
|||||||
* float/double values, but since we are not interested in using the numeric
|
* float/double values, but since we are not interested in using the numeric
|
||||||
* values here, we use a generic handler which uses numeric strings
|
* values here, we use a generic handler which uses numeric strings
|
||||||
*/
|
*/
|
||||||
static int yajl_number(void *ctx, const unsigned char *value, unsigned int length)
|
static int yajl_number(void *ctx, const char *value, size_t length)
|
||||||
{
|
{
|
||||||
modsec_rec *msr = (modsec_rec *) ctx;
|
modsec_rec *msr = (modsec_rec *) ctx;
|
||||||
|
|
||||||
@ -222,19 +222,18 @@ int json_init(modsec_rec *msr, char **error_msg) {
|
|||||||
/**
|
/**
|
||||||
* yajl configuration and callbacks
|
* yajl configuration and callbacks
|
||||||
*/
|
*/
|
||||||
static yajl_parser_config config = { 0, 1 };
|
|
||||||
static yajl_callbacks callbacks = {
|
static yajl_callbacks callbacks = {
|
||||||
yajl_null,
|
yajl_null,
|
||||||
yajl_boolean,
|
yajl_boolean,
|
||||||
NULL /* yajl_integer */,
|
NULL /* yajl_integer */,
|
||||||
NULL /* yajl_double */,
|
NULL /* yajl_double */,
|
||||||
yajl_number,
|
yajl_number,
|
||||||
yajl_string,
|
yajl_string,
|
||||||
yajl_start_map,
|
yajl_start_map,
|
||||||
yajl_map_key,
|
yajl_map_key,
|
||||||
yajl_end_map,
|
yajl_end_map,
|
||||||
NULL /* yajl_start_array */,
|
NULL /* yajl_start_array */,
|
||||||
NULL /* yajl_end_array */
|
NULL /* yajl_end_array */
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error_msg == NULL) return -1;
|
if (error_msg == NULL) return -1;
|
||||||
@ -261,7 +260,7 @@ int json_init(modsec_rec *msr, char **error_msg) {
|
|||||||
if (msr->txcfg->debuglog_level >= 9) {
|
if (msr->txcfg->debuglog_level >= 9) {
|
||||||
msr_log(msr, 9, "yajl JSON parsing callback initialization");
|
msr_log(msr, 9, "yajl JSON parsing callback initialization");
|
||||||
}
|
}
|
||||||
msr->json->handle = yajl_alloc(&callbacks, &config, NULL, msr);
|
msr->json->handle = yajl_alloc(&callbacks, NULL, msr);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -275,8 +274,7 @@ int json_process_chunk(modsec_rec *msr, const char *buf, unsigned int size, char
|
|||||||
|
|
||||||
/* Feed our parser and catch any errors */
|
/* Feed our parser and catch any errors */
|
||||||
msr->json->status = yajl_parse(msr->json->handle, buf, size);
|
msr->json->status = yajl_parse(msr->json->handle, buf, size);
|
||||||
if (msr->json->status != yajl_status_ok &&
|
if (msr->json->status != yajl_status_ok) {
|
||||||
msr->json->status != yajl_status_insufficient_data) {
|
|
||||||
/* We need to free the yajl error message later, how to do this? */
|
/* We need to free the yajl error message later, how to do this? */
|
||||||
*error_msg = yajl_get_error(msr->json->handle, 0, buf, size);
|
*error_msg = yajl_get_error(msr->json->handle, 0, buf, size);
|
||||||
}
|
}
|
||||||
@ -294,9 +292,8 @@ int json_complete(modsec_rec *msr, char **error_msg) {
|
|||||||
*error_msg = NULL;
|
*error_msg = NULL;
|
||||||
|
|
||||||
/* Wrap up the parsing process */
|
/* Wrap up the parsing process */
|
||||||
msr->json->status = yajl_parse_complete(msr->json->handle);
|
msr->json->status = yajl_complete_parse(msr->json->handle);
|
||||||
if (msr->json->status != yajl_status_ok &&
|
if (msr->json->status != yajl_status_ok) {
|
||||||
msr->json->status != yajl_status_insufficient_data) {
|
|
||||||
/* We need to free the yajl error message later, how to do this? */
|
/* We need to free the yajl error message later, how to do this? */
|
||||||
*error_msg = yajl_get_error(msr->json->handle, 0, NULL, 0);
|
*error_msg = yajl_get_error(msr->json->handle, 0, NULL, 0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user