diff options
author | Li Yuxuan <liyuxuan.darfux@bytedance.com> | 2023-03-09 11:11:28 +0800 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2023-03-09 21:33:43 +0000 |
commit | 78635d55fb819d422d0c4c32bb63aab95f735e4b (patch) | |
tree | a6dcf901e402ff45be29d57ed76f622f910c4b3c /lib/audit_logging | |
parent | 35aa7db641484b33ff55a7d8fe2d21c6b411f847 (diff) | |
download | samba-78635d55fb819d422d0c4c32bb63aab95f735e4b.tar.gz |
audit_logging: Use `json_int_t` instead of `int` for `json_add_int` value type
Functions like `add_lock_to_json` and `add_profile_item_to_json` pass
some values to `json_add_int` with `intmax_t` types. This may cause
arithmetic overflow when the value grows very fast, such as the
read_bytes profiling data.
Use `json_add_int` instead of `int` to avoid the overflow.
RN: Make json output show intmax_t value properly
Signed-off-by: Li Yuxuan <liyuxuan.darfux@bytedance.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Mar 9 21:33:43 UTC 2023 on atb-devel-224
Diffstat (limited to 'lib/audit_logging')
-rw-r--r-- | lib/audit_logging/audit_logging.c | 14 | ||||
-rw-r--r-- | lib/audit_logging/audit_logging.h | 2 |
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/audit_logging/audit_logging.c b/lib/audit_logging/audit_logging.c index 43acf9512c9..3ab14b2a187 100644 --- a/lib/audit_logging/audit_logging.c +++ b/lib/audit_logging/audit_logging.c @@ -385,31 +385,33 @@ bool json_is_invalid(const struct json_object *object) * -1 the operation failed * */ -int json_add_int(struct json_object *object, const char *name, const int value) +int json_add_int(struct json_object *object, const char *name, const json_int_t value) { int ret = 0; json_t *integer = NULL; if (json_is_invalid(object)) { - DBG_ERR("Unable to add int [%s] value [%d], " + DBG_ERR("Unable to add int [%s] value [%jd], " "target object is invalid\n", name, - value); + (intmax_t)value); return JSON_ERROR; } integer = json_integer(value); if (integer == NULL) { - DBG_ERR("Unable to create integer value [%s] value [%d]\n", + DBG_ERR("Unable to create integer value [%s] value [%jd]\n", name, - value); + (intmax_t)value); return JSON_ERROR; } ret = json_object_set_new(object->root, name, integer); if (ret != 0) { json_decref(integer); - DBG_ERR("Unable to add int [%s] value [%d]\n", name, value); + DBG_ERR("Unable to add int [%s] value [%jd]\n", + name, + (intmax_t)value); } return ret; } diff --git a/lib/audit_logging/audit_logging.h b/lib/audit_logging/audit_logging.h index 49576ece68d..eb7c103944d 100644 --- a/lib/audit_logging/audit_logging.h +++ b/lib/audit_logging/audit_logging.h @@ -58,7 +58,7 @@ _WARN_UNUSED_RESULT_ bool json_is_invalid(const struct json_object *object); _WARN_UNUSED_RESULT_ int json_add_int(struct json_object *object, const char *name, - const int value); + const json_int_t value); _WARN_UNUSED_RESULT_ int json_add_bool(struct json_object *object, const char *name, const bool value); |