Blame SOURCES/popt-1.18-imp-covscan-fixes.patch

3960f0
commit 7e60d11c1b046e54378cf79280f4a856741c8749
3960f0
Author: Tobias Stoeckmann <tobias@stoeckmann.org>
3960f0
Date:   Sat Aug 22 14:09:58 2020 +0200
3960f0
3960f0
    Close iconv in case of allocation error
3960f0
    
3960f0
    If memory allocation in strdup_locale_from_utf8 fails after calling
3960f0
    iconv_open, the returned conversion descriptor is not closed.
3960f0
3960f0
diff --git a/src/poptint.c b/src/poptint.c
3960f0
index 0cec176..3a0919a 100644
3960f0
--- a/src/poptint.c
3960f0
+++ b/src/poptint.c
3960f0
@@ -91,8 +91,10 @@ strdup_locale_from_utf8 (char * istr)
3960f0
 	size_t ob = db;
3960f0
 	size_t err;
3960f0
 
3960f0
-	if (dstr == NULL)
3960f0
+	if (dstr == NULL) {
3960f0
+	    (void) iconv_close(cd);
3960f0
 	    return NULL;
3960f0
+	}
3960f0
 	err = iconv(cd, NULL, NULL, NULL, NULL);
3960f0
 	while (1) {
3960f0
 	    *pout = '\0';
3960f0
commit 70011cc5763dca9a9b57e9539b465e00c9769996
3960f0
Author: Michal Domonkos <mdomonko@redhat.com>
3960f0
Date:   Mon Jul 19 14:41:03 2021 +0200
3960f0
3960f0
    Fix potential mem leak in poptReadConfigFile()
3960f0
    
3960f0
    While it seems that the actual implementation of poptReadFile()
3960f0
    shouldn't allocate the passed buffer (b) if the number of bytes (nb) is
3960f0
    zero (see the read(2) call in that function), it's still up to the
3960f0
    caller to take care of this resource, so let's just do that by bailing
3960f0
    out via "exit" where the freeing happens.
3960f0
    
3960f0
    Also initialize t to NULL to avoid freeing an undefined pointer.
3960f0
    
3960f0
    Found by Coverity.
3960f0
3960f0
diff --git a/src/poptconfig.c b/src/poptconfig.c
3960f0
index 8623ba2..7c52315 100644
3960f0
--- a/src/poptconfig.c
3960f0
+++ b/src/poptconfig.c
3960f0
@@ -344,13 +344,15 @@ int poptReadConfigFile(poptContext con, const char * fn)
3960f0
     char * b = NULL, *be;
3960f0
     size_t nb = 0;
3960f0
     const char *se;
3960f0
-    char *t, *te;
3960f0
+    char *t = NULL, *te;
3960f0
     int rc;
3960f0
 
3960f0
     if ((rc = poptReadFile(fn, &b, &nb, POPT_READFILE_TRIMNEWLINES)) != 0)
3960f0
 	return (errno == ENOENT ? 0 : rc);
3960f0
-    if (b == NULL || nb == 0)
3960f0
-	return POPT_ERROR_BADCONFIG;
3960f0
+    if (b == NULL || nb == 0) {
3960f0
+	rc = POPT_ERROR_BADCONFIG;
3960f0
+	goto exit;
3960f0
+    }
3960f0
 
3960f0
     if ((t = malloc(nb + 1)) == NULL)
3960f0
 	goto exit;