Blame SOURCES/0004-INI-fix-check-for-error-code.patch

76347b
From ec6817736968fb4683b9df0bd932c1a86dec0ba8 Mon Sep 17 00:00:00 2001
76347b
From: Alexey Tikhonov <atikhono@redhat.com>
76347b
Date: Wed, 4 Aug 2021 19:22:19 +0200
76347b
Subject: [PATCH 4/6] INI: fix check for error code
76347b
76347b
In case of fail `asprintf()` returns -1, not 1.
76347b
76347b
Fixes following covscan issues:
76347b
```
76347b
Error: RESOURCE_LEAK (CWE-772): [#def1]
76347b
ding-libs-0.6.1/ini/ini_configmod.c:869: alloc_arg: "asprintf" allocates memory that is stored into "strval". [Note: The source code implementation of the function has been overridden by a builtin model.]
76347b
ding-libs-0.6.1/ini/ini_configmod.c:873: leaked_storage: Variable "strval" going out of scope leaks the storage it points to.
76347b
 #  871|           TRACE_ERROR_NUMBER("Asprintf failed.", ret);
76347b
 #  872|           /* The main reason is propbaly memory allocation */
76347b
 #  873|->         return ENOMEM;
76347b
 #  874|       }
76347b
 #  875|
76347b
```
76347b
76347b
Reviewed-by: Pawel Polawski <ppolawsk@redhat.com>
76347b
---
76347b
 ini/ini_configmod.c | 2 +-
76347b
 1 file changed, 1 insertion(+), 1 deletion(-)
76347b
76347b
diff --git a/ini/ini_configmod.c b/ini/ini_configmod.c
76347b
index da4175c..88a7133 100644
76347b
--- a/ini/ini_configmod.c
76347b
+++ b/ini/ini_configmod.c
76347b
@@ -867,7 +867,7 @@ int ini_config_add_double_value(struct ini_cfgobj *ini_config,
76347b
     TRACE_FLOW_ENTRY();
76347b
 
76347b
     ret = asprintf(&strval, "%f", value);
76347b
-    if (ret == 1) {
76347b
+    if (ret == -1) {
76347b
         TRACE_ERROR_NUMBER("Asprintf failed.", ret);
76347b
         /* The main reason is propbaly memory allocation */
76347b
         return ENOMEM;
76347b
-- 
76347b
2.26.3
76347b