[SSSD] [PATCH] Autofs Coverity issues

Jakub Hrozek jhrozek at redhat.com
Wed Mar 7 13:56:15 UTC 2012


[PATCH 1/2] Autofs: operate on contents of double-pointer, not address
This is a bad one, luckily the code is defensive later on and detects
that we have processed all the records and quits correctly.

[PATCH 2/2] Only free returned values on success
The pointers are set to NULL when the map is not found or the code
iterates over all the maps, but it is good manners to only free the data
when the caller is sure he received any.
-------------- next part --------------
From f1c97b1e5c6f84bdab398972e4631012e7628a72 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Wed, 7 Mar 2012 13:45:36 +0100
Subject: [PATCH 1/2] Autofs: operate on contents of double-pointer, not
 address

https://fedorahosted.org/sssd/ticket/1234
---
 src/sss_client/autofs/sss_autofs.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/sss_client/autofs/sss_autofs.c b/src/sss_client/autofs/sss_autofs.c
index 218c1ed7935cf3fcce7fc113b3926c19470d0257..631e88a4575f212b921e996c21b71ecb8cde156c 100644
--- a/src/sss_client/autofs/sss_autofs.c
+++ b/src/sss_client/autofs/sss_autofs.c
@@ -220,15 +220,15 @@ sss_getautomntent_data_save(const char *mapname, uint8_t **repbuf, size_t replen
     uint32_t num;
 
     rp = 0;
-    SAFEALIGN_COPY_UINT32(&num, repbuf+rp, &rp);
+    SAFEALIGN_COPY_UINT32(&num, *repbuf+rp, &rp);
     if (num == 0) {
-        free(repbuf);
+        free(*repbuf);
         return ENOENT;
     }
 
     sss_getautomntent_data.mapname = strdup(mapname);
     if (sss_getautomntent_data.mapname == NULL) {
-        free(repbuf);
+        free(*repbuf);
         return ENOENT;
     }
 
-- 
1.7.7.6

-------------- next part --------------
From 40896e02f14c06c1e4ee73ef624b138fe8c30461 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Wed, 7 Mar 2012 14:44:46 +0100
Subject: [PATCH 2/2] Only free returned values on success

https://fedorahosted.org/sssd/ticket/1237
---
 src/sss_client/autofs/autofs_test_client.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/sss_client/autofs/autofs_test_client.c b/src/sss_client/autofs/autofs_test_client.c
index 6e95c17498437d0c72d5b51219d1b8c97216a9e7..386c890c6cc8213a219306303503a6e24bc1c8dc 100644
--- a/src/sss_client/autofs/autofs_test_client.c
+++ b/src/sss_client/autofs/autofs_test_client.c
@@ -79,9 +79,9 @@ int main(int argc, const char *argv[])
             ret = _sss_getautomntent_r(&key, &value, ctx);
             if (ret == 0) {
                 printf("key: %s\t\tvalue: %s\n", key, value);
+                free(key);
+                free(value);
             }
-            free(key);
-            free(value);
         } while(ret == 0);
 
         if (ret != 0 && ret != ENOENT) {
@@ -99,8 +99,8 @@ int main(int argc, const char *argv[])
             exit(EXIT_FAILURE);
         } else {
             printf("key: %s\t\tvalue: %s\n", pc_key, value);
+            free(value);
         }
-        free(value);
     }
 
     ret = _sss_endautomntent(&ctx);
-- 
1.7.7.6



More information about the sssd-devel mailing list