]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
audit_logging: Use `json_int_t` instead of `int` for `json_add_int` value type
authorLi Yuxuan <liyuxuan.darfux@bytedance.com>
Thu, 9 Mar 2023 03:11:28 +0000 (11:11 +0800)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 9 Mar 2023 21:33:43 +0000 (21:33 +0000)
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

lib/audit_logging/audit_logging.c
lib/audit_logging/audit_logging.h
selftest/knownfail.d/json_add_int [deleted file]

index 43acf9512c98424e580e16cfedf83127a4c16e90..3ab14b2a187786fd72be3979802d80777c1e7bef 100644 (file)
@@ -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;
 }
index 49576ece68df2090401e3d94c70e3a58e51a91ab..eb7c103944db81409b235328fa1f6dee28a9f733 100644 (file)
@@ -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);
diff --git a/selftest/knownfail.d/json_add_int b/selftest/knownfail.d/json_add_int
deleted file mode 100644 (file)
index 0ccf8c0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-lib.audit_logging.audit_logging.test_json_add_int\(none\)