Fix bug 6811 - pam_winbind references freed memory. s3: Fix reference to freed memory...
authorBo Yang <boyang@samba.org>
Wed, 14 Oct 2009 19:47:49 +0000 (12:47 -0700)
committerKarolin Seeger <kseeger@samba.org>
Wed, 13 Jan 2010 13:00:47 +0000 (14:00 +0100)
(cherry picked from commit 80c18ba49f4751dc104062de6a438f00a7afc39d)

source/nsswitch/pam_winbind.c

index 4dcfe73533d3b804f509aafd5a691e9bc5fa7070..0dcd084f33a324883945b877e7def2a498a5bd5e 100644 (file)
@@ -976,7 +976,8 @@ static bool winbind_name_to_sid_string(struct pwb_context *ctx,
                                       char *sid_list_buffer,
                                       int sid_list_buffer_size)
 {
-       const char* sid_string;
+       const char* sid_string = NULL;
+       char *sid_str = NULL;
 
        /* lookup name? */
        if (IS_SID_STRING(name)) {
@@ -985,7 +986,6 @@ static bool winbind_name_to_sid_string(struct pwb_context *ctx,
                wbcErr wbc_status;
                struct wbcDomainSid sid;
                enum wbcSidType type;
-               char *sid_str;
 
                _pam_log_debug(ctx, LOG_DEBUG,
                               "no sid given, looking up: %s\n", name);
@@ -1002,15 +1002,16 @@ static bool winbind_name_to_sid_string(struct pwb_context *ctx,
                        return false;
                }
 
-               wbcFreeMemory(sid_str);
                sid_string = sid_str;
        }
 
        if (!safe_append_string(sid_list_buffer, sid_string,
                                sid_list_buffer_size)) {
+               wbcFreeMemory(sid_str);
                return false;
        }
 
+       wbcFreeMemory(sid_str);
        return true;
 }