Blame SOURCES/0039-pam_sss_gssapi-fix-coverity-issues.patch

b833e0
From 111b8b4d62a4fe192c075e6f6bfacb408e6074b3 Mon Sep 17 00:00:00 2001
b833e0
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
b833e0
Date: Tue, 12 Jan 2021 13:50:11 +0100
b833e0
Subject: [PATCH 39/39] pam_sss_gssapi: fix coverity issues
b833e0
MIME-Version: 1.0
b833e0
Content-Type: text/plain; charset=UTF-8
b833e0
Content-Transfer-Encoding: 8bit
b833e0
b833e0
```
b833e0
1. Defect type: RESOURCE_LEAK
b833e0
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:556: leaked_storage: Variable "username" going out of scope leaks the storage it points to.
b833e0
Expand
b833e0
2. Defect type: RESOURCE_LEAK
b833e0
3. sssd-2.4.0/src/sss_client/pam_sss_gss.c:321: leaked_storage: Variable "reply" going out of scope leaks the storage it points to.
b833e0
Expand
b833e0
3. Defect type: RESOURCE_LEAK
b833e0
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "username" going out of scope leaks the storage it points to.
b833e0
Expand
b833e0
4. Defect type: RESOURCE_LEAK
b833e0
6. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "upn" going out of scope leaks the storage it points to.
b833e0
Expand
b833e0
5. Defect type: RESOURCE_LEAK
b833e0
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "target" going out of scope leaks the storage it points to.
b833e0
Expand
b833e0
6. Defect type: RESOURCE_LEAK
b833e0
7. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260: leaked_storage: Variable "domain" going out of scope leaks the storage it points to.
b833e0
b833e0
1. Defect type: CLANG_WARNING
b833e0
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'username'
b833e0
Expand
b833e0
2. Defect type: CLANG_WARNING
b833e0
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'upn'
b833e0
Expand
b833e0
3. Defect type: CLANG_WARNING
b833e0
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'target'
b833e0
Expand
b833e0
4. Defect type: CLANG_WARNING
b833e0
1. sssd-2.4.0/src/sss_client/pam_sss_gss.c:260:16: warning[unix.Malloc]: Potential leak of memory pointed to by 'domain'
b833e0
```
b833e0
b833e0
Also fix compilation warning
b833e0
```
b833e0
../src/sss_client/pam_sss_gss.c:339:5: warning: ‘reply’ may be used uninitialized in this function [-Wmaybe-uninitialized]
b833e0
  339 |     free(reply);
b833e0
      |     ^~~~~~~~~~~
b833e0
../src/sss_client/pam_sss_gss.c:328:14: note: ‘reply’ was declared here
b833e0
  328 |     uint8_t *reply;
b833e0
      |              ^~~~~
b833e0
../src/sss_client/pam_sss_gss.c:270:11: warning: ‘reply_len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
b833e0
  270 |     upn = malloc(reply_len * sizeof(char));
b833e0
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
b833e0
../src/sss_client/pam_sss_gss.c:327:12: note: ‘reply_len’ was declared here
b833e0
  327 |     size_t reply_len;
b833e0
      |            ^~~~~~~~~
b833e0
```
b833e0
b833e0
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
b833e0
Reviewed-by: Sumit Bose <sbose@redhat.com>
b833e0
---
b833e0
 src/sss_client/pam_sss_gss.c | 22 ++++++++++++++++++----
b833e0
 1 file changed, 18 insertions(+), 4 deletions(-)
b833e0
b833e0
diff --git a/src/sss_client/pam_sss_gss.c b/src/sss_client/pam_sss_gss.c
b833e0
index cd38db7da..51be36ece 100644
b833e0
--- a/src/sss_client/pam_sss_gss.c
b833e0
+++ b/src/sss_client/pam_sss_gss.c
b833e0
@@ -195,6 +195,8 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
b833e0
     struct sss_cli_req_data req_data;
b833e0
     size_t service_len;
b833e0
     size_t user_len;
b833e0
+    size_t reply_len;
b833e0
+    uint8_t *reply = NULL;
b833e0
     uint8_t *data;
b833e0
     errno_t ret;
b833e0
     int ret_errno;
b833e0
@@ -217,7 +219,7 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
b833e0
 
b833e0
     req_data.data = data;
b833e0
 
b833e0
-    ret = sss_pam_make_request(SSS_GSSAPI_INIT, &req_data, _reply, _reply_len,
b833e0
+    ret = sss_pam_make_request(SSS_GSSAPI_INIT, &req_data, &reply, &reply_len,
b833e0
                                &ret_errno);
b833e0
     free(data);
b833e0
     if (ret != PAM_SUCCESS) {
b833e0
@@ -233,6 +235,16 @@ static errno_t sssd_gssapi_init_send(pam_handle_t *pamh,
b833e0
         return (ret_errno != EOK) ? ret_errno : EIO;
b833e0
     }
b833e0
 
b833e0
+    if (ret_errno == EOK) {
b833e0
+        *_reply = reply;
b833e0
+        *_reply_len = reply_len;
b833e0
+    } else {
b833e0
+        /* We got PAM_SUCCESS therefore the communication with SSSD was
b833e0
+         * successful and we have received a reply buffer. We just don't care
b833e0
+         * about it, we are only interested in the error code. */
b833e0
+        free(reply);
b833e0
+    }
b833e0
+
b833e0
     return ret_errno;
b833e0
 }
b833e0
 
b833e0
@@ -257,7 +269,8 @@ static errno_t sssd_gssapi_init_recv(uint8_t *reply,
b833e0
     target = malloc(reply_len * sizeof(char));
b833e0
     upn = malloc(reply_len * sizeof(char));
b833e0
     if (username == NULL || domain == NULL || target == NULL || upn == NULL) {
b833e0
-        return ENOMEM;
b833e0
+        ret = ENOMEM;
b833e0
+        goto done;
b833e0
     }
b833e0
 
b833e0
     buf = (const char*)reply;
b833e0
@@ -311,8 +324,8 @@ static errno_t sssd_gssapi_init(pam_handle_t *pamh,
b833e0
                                 char **_target,
b833e0
                                 char **_upn)
b833e0
 {
b833e0
-    size_t reply_len;
b833e0
-    uint8_t *reply;
b833e0
+    size_t reply_len = 0;
b833e0
+    uint8_t *reply = NULL;
b833e0
     errno_t ret;
b833e0
 
b833e0
     ret = sssd_gssapi_init_send(pamh, pam_service, pam_user, &reply,
b833e0
@@ -549,6 +562,7 @@ int pam_sm_authenticate(pam_handle_t *pamh,
b833e0
 
b833e0
 done:
b833e0
     sss_pam_close_fd();
b833e0
+    free(username);
b833e0
     free(domain);
b833e0
     free(target);
b833e0
     free(upn);
b833e0
-- 
b833e0
2.21.3
b833e0