mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
audit_logging: Simplify json_add_stringn() with json_stringn()
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Aug 14 20:51:11 UTC 2023 on atb-devel-224
This commit is contained in:
parent
a9f358f7d7
commit
42e4691cf5
@ -644,13 +644,7 @@ int json_add_stringn(struct json_object *object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (value != NULL && len > 0) {
|
if (value != NULL && len > 0) {
|
||||||
json_t *string = NULL;
|
json_t *string = json_stringn(value, len);
|
||||||
char buffer[len+1];
|
|
||||||
|
|
||||||
strncpy(buffer, value, len);
|
|
||||||
buffer[len] = '\0';
|
|
||||||
|
|
||||||
string = json_string(buffer);
|
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
DBG_ERR("Unable to add string [%s], "
|
DBG_ERR("Unable to add string [%s], "
|
||||||
"could not create string object\n",
|
"could not create string object\n",
|
||||||
|
@ -118,6 +118,21 @@ json_t *__wrap_json_string(const char *value)
|
|||||||
return __real_json_string(value);
|
return __real_json_string(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* cmocka wrappers for json_stringn
|
||||||
|
*/
|
||||||
|
json_t *__wrap_json_stringn(const char *value, size_t len);
|
||||||
|
json_t *__real_json_stringn(const char *value, size_t len);
|
||||||
|
json_t *__wrap_json_stringn(const char *value, size_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
bool fail = (bool)mock();
|
||||||
|
if (fail) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return __real_json_stringn(value, len);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* cmocka wrappers for json_dumps
|
* cmocka wrappers for json_dumps
|
||||||
*/
|
*/
|
||||||
@ -510,7 +525,7 @@ static void test_json_add_stringn(_UNUSED_ void **state)
|
|||||||
/*
|
/*
|
||||||
* Test json string failure
|
* Test json string failure
|
||||||
*/
|
*/
|
||||||
will_return(__wrap_json_string, true);
|
will_return(__wrap_json_stringn, true);
|
||||||
rc = json_add_stringn(&object, "name", "value", 3);
|
rc = json_add_stringn(&object, "name", "value", 3);
|
||||||
|
|
||||||
assert_false(json_is_invalid(&object));
|
assert_false(json_is_invalid(&object));
|
||||||
@ -519,7 +534,7 @@ static void test_json_add_stringn(_UNUSED_ void **state)
|
|||||||
/*
|
/*
|
||||||
* Test json object set new failure
|
* Test json object set new failure
|
||||||
*/
|
*/
|
||||||
will_return(__wrap_json_string, false);
|
will_return(__wrap_json_stringn, false);
|
||||||
will_return(__wrap_json_object_set_new, JANSSON_FAILURE);
|
will_return(__wrap_json_object_set_new, JANSSON_FAILURE);
|
||||||
rc = json_add_stringn(&object, "name", "value", 3);
|
rc = json_add_stringn(&object, "name", "value", 3);
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ if bld.AD_DC_BUILD_IS_ENABLED():
|
|||||||
-Wl,--wrap,json_array_extend
|
-Wl,--wrap,json_array_extend
|
||||||
-Wl,--wrap,json_object
|
-Wl,--wrap,json_object
|
||||||
-Wl,--wrap,json_string
|
-Wl,--wrap,json_string
|
||||||
|
-Wl,--wrap,json_stringn
|
||||||
-Wl,--wrap,json_integer
|
-Wl,--wrap,json_integer
|
||||||
-Wl,--wrap,json_array
|
-Wl,--wrap,json_array
|
||||||
-Wl,--wrap,json_dumps
|
-Wl,--wrap,json_dumps
|
||||||
|
Loading…
Reference in New Issue
Block a user