Blame SOURCES/Fix-error-handling-in-gpm_send_buffer-gpm_recv_buffe.patch

1f3433
From accc0e772b126d251ca853a080b25466ebc528a3 Mon Sep 17 00:00:00 2001
1f3433
From: Alexander Scheel <alexander.m.scheel@gmail.com>
1f3433
Date: Thu, 14 Sep 2017 11:24:39 -0500
1f3433
Subject: [PATCH] Fix error handling in gpm_send_buffer/gpm_recv_buffer
1f3433
1f3433
Signed-off-by: Alexander Scheel <alexander.m.scheel@gmail.com>
1f3433
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
1f3433
Merges: #213
1f3433
[rharwood@redhat.com: commit message formatting, copyright update]
1f3433
(cherry picked from commit f2530fc280dd84e6abc0f5475e261aa0d2ee2a21)
1f3433
---
1f3433
 proxy/src/client/gpm_common.c | 18 ++++++------------
1f3433
 1 file changed, 6 insertions(+), 12 deletions(-)
1f3433
1f3433
diff --git a/proxy/src/client/gpm_common.c b/proxy/src/client/gpm_common.c
1f3433
index b14e846..0d314fa 100644
1f3433
--- a/proxy/src/client/gpm_common.c
1f3433
+++ b/proxy/src/client/gpm_common.c
1f3433
@@ -1,4 +1,4 @@
1f3433
-/* Copyright (C) 2011 the GSS-PROXY contributors, see COPYING for license */
1f3433
+/* Copyright (C) 2011,2017 the GSS-PROXY contributors, see COPYING for license */
1f3433
 
1f3433
 #include "gssapi_gpm.h"
1f3433
 #include <sys/types.h>
1f3433
@@ -415,10 +415,7 @@ static int gpm_send_buffer(struct gpm_ctx *gpmctx,
1f3433
     ret = 0;
1f3433
 
1f3433
 done:
1f3433
-    if (ret) {
1f3433
-        /* on errors we can only close the fd and return */
1f3433
-        gpm_close_socket(gpmctx);
1f3433
-    }
1f3433
+    /* we only need to return as gpm_retry_socket closes the socket */
1f3433
     return ret;
1f3433
 }
1f3433
 
1f3433
@@ -488,9 +485,10 @@ static int gpm_recv_buffer(struct gpm_ctx *gpmctx,
1f3433
 
1f3433
 done:
1f3433
     if (ret) {
1f3433
-        /* on errors we can only close the fd and return */
1f3433
-        gpm_close_socket(gpmctx);
1f3433
-        gpm_epoll_close(gpmctx);
1f3433
+        /* on errors, free the buffer to prevent calling
1f3433
+         * xdr_destroy(&xdr_reply_ctx); */
1f3433
+        free(*buffer);
1f3433
+        *buffer = NULL;
1f3433
     }
1f3433
     return ret;
1f3433
 }
1f3433
@@ -560,10 +558,6 @@ static int gpm_send_recv_loop(struct gpm_ctx *gpmctx, char *send_buffer,
1f3433
             /* Close and reopen socket before trying again */
1f3433
             ret = gpm_retry_socket(gpmctx);
1f3433
 
1f3433
-            /* Free buffer and set it to NULL to prevent free(xdr_reply_ctx) */
1f3433
-            free(*recv_buffer);
1f3433
-            *recv_buffer = NULL;
1f3433
-
1f3433
             if (ret != 0)
1f3433
                 return ret;
1f3433
             ret = ETIMEDOUT;