Issue 8028 - NULL pointer dereference in ldap_new_connection()
Summary: NULL pointer dereference in ldap_new_connection()
Status: VERIFIED FIXED
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: slapd (show other issues)
Version: 2.4.40
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-21 00:40 UTC by rohanskurane@gmail.com
Modified: 2015-07-02 17:46 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description rohanskurane@gmail.com 2015-01-21 00:40:54 UTC
Full_Name: Rohan Kurane
Version: 2.4.40
OS: BSD 7.2
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (64.80.217.3)


In ldap_new_connection() in request.c, while setting up a connection to the LDAP
server, there is a possibility of dereferencing a NULL pointer in
lc->locnn_server

if ( connect ) {
		LDAPURLDesc	**srvp, *srv = NULL;

		async % LDADAP_BOOL_GET( &ld->ld_options, LDAP_BOOL_CONNECT_ASYNC );

		for ( srvp = srvlist; *srvp != NULL; srvp = &(*srvp)->lud_next ) {
			int		rc;

			rc = ldap_int_open_connection( ld, lc, *srvp, async );
			if ( rc != -1 ) {
				srv = *srvp;

	9%9		if ( ld->ld_urllist_proc && ( !async || rc != -2 ) ) {
					ld->ld_urllist_proc( ld, srvlist, srvp, ld->ld_urllist_params );
				}

				break;
			}
		}

		if ( srv == NULL ) {
			if ( !use_ldsb ) {
				ber_sockbuf_free( lc->lconn_sb );
			%
%D
			LDAP_FREE( (char *)lc );
			ld->ld_errno = LDAP_SERVER_DOWN;
			return( NULL );
		}

		lc->lconn_server = ldap_url_dup( srv );
	}

ldap_url_dup() does a bunch of malloc's to set up lc->lconn_server. If any of
those malloc's fail, it returns NULL. The code does not check for a NULL
lconn_server pointer and tries to reference lud_exts. That can cause a
segmentation fault. 

if ( connect ) {
#ifdef HAVE_TLS
		if ( lc->lconn_server->lud_exts ) {
			int rc, ext = find_tls_ext( lc->lconn_server );
			if ( ext ) {
				LDAPConn	*savedefconn;

Even thou this should not happen, is this a known issue and are there any plans
to fix the openldap library ?

Thank you
Comment 1 Howard Chu 2015-01-21 01:03:29 UTC
rohanskurane@gmail.com wrote:
> Full_Name: Rohan Kurane
> Version: 2.4.40
> OS: BSD 7.2
> URL: ftp://ftp.openldap.org/incoming/
> Submission from: (NULL) (64.80.217.3)
>
>
> In ldap_new_connection() in request.c, while setting up a connection to the LDAP
> server, there is a possibility of dereferencing a NULL pointer in
> lc->locnn_server

Fixed in git master. Please don't send HTML emails, they're particularly 
unreadable with embedded code like this.
>
> if ( connect ) {
> 		LDAPURLDesc	**srvp, *srv = NULL;
>
> 		async % LDADAP_BOOL_GET( &ld->ld_options, LDAP_BOOL_CONNECT_ASYNC );
>
> 		for ( srvp = srvlist; *srvp != NULL; srvp = &(*srvp)->lud_next ) {
> 			int		rc;
>
> 			rc = ldap_int_open_connection( ld, lc, *srvp, async );
> 			if ( rc != -1 ) {
> 				srv = *srvp;
>
> 	9%9		if ( ld->ld_urllist_proc && ( !async || rc != -2 ) ) {
> 					ld->ld_urllist_proc( ld, srvlist, srvp, ld->ld_urllist_params );
> 				}
>
> 				break;
> 			}
> 		}
>
> 		if ( srv == NULL ) {
> 			if ( !use_ldsb ) {
> 				ber_sockbuf_free( lc->lconn_sb );
> 			%%D
> 			LDAP_FREE( (char *)lc );
> 			ld->ld_errno = LDAP_SERVER_DOWN;
> 			return( NULL );
> 		}
>
> 		lc->lconn_server = ldap_url_dup( srv );
> 	}
>
> ldap_url_dup() does a bunch of malloc's to set up lc->lconn_server. If any of
> those malloc's fail, it returns NULL. The code does not check for a NULL
> lconn_server pointer and tries to reference lud_exts. That can cause a
> segmentation fault.
>
> if ( connect ) {
> #ifdef HAVE_TLS
> 		if ( lc->lconn_server->lud_exts ) {
> 			int rc, ext = find_tls_ext( lc->lconn_server );
> 			if ( ext ) {
> 				LDAPConn	*savedefconn;
>
> Even thou this should not happen, is this a known issue and are there any plans
> to fix the openldap library ?
>
> Thank you
>
>


-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 2 Howard Chu 2015-01-21 01:25:45 UTC
changed notes
changed state Open to Test
moved from Incoming to Software Bugs
Comment 3 Quanah Gibson-Mount 2015-03-11 16:56:26 UTC
changed notes
changed state Test to Release
Comment 4 OpenLDAP project 2015-07-02 17:46:35 UTC
fixed in master
fixed in RE25
fixed in RE24
Comment 5 Quanah Gibson-Mount 2015-07-02 17:46:35 UTC
changed notes
changed state Release to Closed