diff options
author | Andreas Schneider <asn@samba.org> | 2018-08-09 16:38:49 +0200 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2018-08-13 19:46:08 +0200 |
commit | 4c0b49b3f982a3a3013a3b6fef3c10b1ca7d2ab0 (patch) | |
tree | 151fb6d29be76a40c6e12adba1358849ebafd666 /source3/winbindd | |
parent | 3e6ce5c6e679fdb39ed8142bf5e1ed4105164826 (diff) | |
download | samba-4c0b49b3f982a3a3013a3b6fef3c10b1ca7d2ab0.tar.gz |
s3:winbind: Fix memory leak in nss_init()
Found by covscan.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13567
Pair-Programmed-With: Justin Stephenson <jstephen@redhat.com>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Justin Stephenson <jstephen@redhat.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/winbindd')
-rw-r--r-- | source3/winbindd/nss_info.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/source3/winbindd/nss_info.c b/source3/winbindd/nss_info.c index 473b1a3b66e..1a8325ce7dc 100644 --- a/source3/winbindd/nss_info.c +++ b/source3/winbindd/nss_info.c @@ -84,7 +84,10 @@ static struct nss_function_entry *nss_get_backend(const char *name ) /******************************************************************** *******************************************************************/ -static bool parse_nss_parm( const char *config, char **backend, char **domain ) +static bool parse_nss_parm(TALLOC_CTX *mem_ctx, + const char *config, + char **backend, + char **domain) { char *p; @@ -98,17 +101,17 @@ static bool parse_nss_parm( const char *config, char **backend, char **domain ) /* if no : then the string must be the backend name only */ if ( !p ) { - *backend = SMB_STRDUP( config ); + *backend = talloc_strdup(mem_ctx, config); return (*backend != NULL); } /* split the string and return the two parts */ if ( strlen(p+1) > 0 ) { - *domain = SMB_STRDUP( p+1 ); + *domain = talloc_strdup(mem_ctx, p + 1); } - *backend = SMB_STRNDUP(config, PTR_DIFF(p, config)); + *backend = talloc_strndup(mem_ctx, config, PTR_DIFF(p, config)); return (*backend != NULL); } @@ -158,8 +161,9 @@ static NTSTATUS nss_init(const char **nss_list) NTSTATUS status; static bool nss_initialized = false; int i; - char *backend, *domain; + char *backend = NULL, *domain = NULL; struct nss_function_entry *nss_backend; + TALLOC_CTX *frame; /* check for previous successful initializations */ @@ -167,6 +171,8 @@ static NTSTATUS nss_init(const char **nss_list) return NT_STATUS_OK; } + frame = talloc_stackframe(); + /* The "template" backend should always be registered as it is a static module */ @@ -179,8 +185,10 @@ static NTSTATUS nss_init(const char **nss_list) as necessary) */ for ( i=0; nss_list && nss_list[i]; i++ ) { + bool ok; - if ( !parse_nss_parm(nss_list[i], &backend, &domain) ) { + ok = parse_nss_parm(frame, nss_list[i], &backend, &domain); + if (!ok) { DEBUG(0,("nss_init: failed to parse \"%s\"!\n", nss_list[i])); continue; @@ -238,10 +246,11 @@ static NTSTATUS nss_init(const char **nss_list) /* cleanup */ - SAFE_FREE( backend ); - SAFE_FREE( domain ); + TALLOC_FREE(domain); + TALLOC_FREE(backend); } + if ( !nss_domain_list ) { DEBUG(3,("nss_init: no nss backends configured. " "Defaulting to \"template\".\n")); @@ -252,6 +261,7 @@ static NTSTATUS nss_init(const char **nss_list) nss_initialized = true; + TALLOC_FREE(frame); return NT_STATUS_OK; } |