From dea7e8ebe9e35ff7029f57e13f6c3adfe91d0479 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 9 Dec 2024 21:33:28 +0900 Subject: [PATCH] Check for spprintf failure in key generation Add a check for negative length returned by spprintf to ensure key generation doesn't proceed with invalid data. This prevents potential issues or crashes that could occur if the function fails and returns an error. --- rayaop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rayaop.c b/rayaop.c index 6ea81b6..f99d373 100644 --- a/rayaop.c +++ b/rayaop.c @@ -106,6 +106,9 @@ PHP_RAYAOP_API char *php_rayaop_generate_key(zend_string *class_name, zend_strin } char *key; int len = spprintf(&key, 0, "%s::%s", ZSTR_VAL(class_name), ZSTR_VAL(method_name)); + if (len < 0) { + return NULL; + } if (key_len) { *key_len = (size_t)len; }