From 866324bcd28c1355fb6d7fdf8ee7a4d790e31718 Mon Sep 17 00:00:00 2001 From: Ingo Franzki Date: Wed, 1 Jul 2026 08:51:30 +0200 Subject: [PATCH] libkmipclient: Fix possible NULL pointer dereference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Function gmtime() might return NULL which would then be passed to strftime(). Return an error in case gmtime() return NULL. Assisted-by: IBM Bob:2.0.0 Signed-off-by: Ingo Franzki Reviewed-by: Finn Callies Signed-off-by: Jan Höppner --- libkmipclient/json.c | 4 ++++ libkmipclient/xml.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/libkmipclient/json.c b/libkmipclient/json.c index ed8e27c7..570c64f1 100644 --- a/libkmipclient/json.c +++ b/libkmipclient/json.c @@ -621,6 +621,10 @@ int kmip_encode_json(const struct kmip_node *node, json_object **obj, case KMIP_TYPE_DATE_TIME: tm = gmtime((time_t *)&node->date_time_value); + if (tm == NULL) { + rc = -EINVAL; + goto out; + } strftime(outstr, sizeof(outstr), KMIP_ISO8601_TIMESTAMP_UTC, tm); memb_obj = json_object_new_string(outstr); diff --git a/libkmipclient/xml.c b/libkmipclient/xml.c index 22766085..61a4e625 100644 --- a/libkmipclient/xml.c +++ b/libkmipclient/xml.c @@ -460,6 +460,10 @@ int kmip_encode_xml(const struct kmip_node *node, xmlNode **xml, bool debug) case KMIP_TYPE_DATE_TIME: tm = gmtime((time_t *)&node->date_time_value); + if (tm == NULL) { + rc = -EINVAL; + goto out; + } strftime(tmp_str, sizeof(tmp_str), KMIP_ISO8601_TIMESTAMP_UTC, tm); attr = xmlSetProp(ret_xml, (xmlChar *)KMIP_XML_VALUE,