|
| 1 | +From c5c8c06a8bd52ea7b843e7d8ca961a7d1800ce5f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Howard Chu <hyc@openldap.org> |
| 3 | +Date: Wed, 24 Aug 2022 14:40:51 +0100 |
| 4 | +Subject: [PATCH] ITS#9904 ldif_open_url: check for ber_strdup failure |
| 5 | + |
| 6 | +Code present since 1999, df8f7cbb9b79be3be9205d116d1dd0b263d6861a |
| 7 | +--- |
| 8 | + libraries/libldap/fetch.c | 2 ++ |
| 9 | + libraries/libldap/url.c | 21 ++++++++++++--------- |
| 10 | + 2 files changed, 14 insertions(+), 9 deletions(-) |
| 11 | + |
| 12 | +diff --git a/libraries/libldap/fetch.c b/libraries/libldap/fetch.c |
| 13 | +index cdc69b8..fe5c4e5 100644 |
| 14 | +--- a/libraries/libldap/fetch.c |
| 15 | ++++ b/libraries/libldap/fetch.c |
| 16 | +@@ -69,6 +69,8 @@ ldif_open_url( |
| 17 | + } |
| 18 | + |
| 19 | + p = ber_strdup( urlstr ); |
| 20 | ++ if ( p == NULL ) |
| 21 | ++ return NULL; |
| 22 | + |
| 23 | + /* But we should convert to LDAP_DIRSEP before use */ |
| 24 | + if ( LDAP_DIRSEP[0] != '/' ) { |
| 25 | +--- |
| 26 | +From 6563fab9e2feccb0a684d0398e78571d09fb808b Mon Sep 17 00:00:00 2001 |
| 27 | +From: Howard Chu <hyc@openldap.org> |
| 28 | +Date: Thu, 25 Aug 2022 16:13:21 +0100 |
| 29 | +Subject: [PATCH] ITS#9904 ldap_url_parsehosts: check for strdup failure |
| 30 | + |
| 31 | +Avoid unnecessary strdup in IPv6 addr parsing, check for strdup |
| 32 | +failure when dup'ing scheme. |
| 33 | + |
| 34 | +Code present since 2000, 8da110a9e726dbc612b302feafe0109271e6bc59 |
| 35 | +--- |
| 36 | +diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c |
| 37 | +index b39f70b..01a167d 100644 |
| 38 | +--- a/libraries/libldap/url.c |
| 39 | ++++ b/libraries/libldap/url.c |
| 40 | +@@ -1357,24 +1357,22 @@ ldap_url_parsehosts( |
| 41 | + } |
| 42 | + ludp->lud_port = port; |
| 43 | + ludp->lud_host = specs[i]; |
| 44 | +- specs[i] = NULL; |
| 45 | + p = strchr(ludp->lud_host, ':'); |
| 46 | + if (p != NULL) { |
| 47 | + /* more than one :, IPv6 address */ |
| 48 | + if ( strchr(p+1, ':') != NULL ) { |
| 49 | + /* allow [address] and [address]:port */ |
| 50 | + if ( *ludp->lud_host == '[' ) { |
| 51 | +- p = LDAP_STRDUP(ludp->lud_host+1); |
| 52 | +- /* copied, make sure we free source later */ |
| 53 | +- specs[i] = ludp->lud_host; |
| 54 | +- ludp->lud_host = p; |
| 55 | +- p = strchr( ludp->lud_host, ']' ); |
| 56 | ++ p = strchr( ludp->lud_host+1, ']' ); |
| 57 | + if ( p == NULL ) { |
| 58 | + LDAP_FREE(ludp); |
| 59 | + ldap_charray_free(specs); |
| 60 | + return LDAP_PARAM_ERROR; |
| 61 | + } |
| 62 | +- *p++ = '\0'; |
| 63 | ++ /* Truncate trailing ']' and shift hostname down 1 char */ |
| 64 | ++ *p = '\0'; |
| 65 | ++ AC_MEMCPY( ludp->lud_host, ludp->lud_host+1, p - ludp->lud_host ); |
| 66 | ++ p++; |
| 67 | + if ( *p != ':' ) { |
| 68 | + if ( *p != '\0' ) { |
| 69 | + LDAP_FREE(ludp); |
| 70 | +@@ -1400,14 +1398,19 @@ ldap_url_parsehosts( |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | +- ldap_pvt_hex_unescape(ludp->lud_host); |
| 75 | + ludp->lud_scheme = LDAP_STRDUP("ldap"); |
| 76 | ++ if ( ludp->lud_scheme == NULL ) { |
| 77 | ++ LDAP_FREE(ludp); |
| 78 | ++ ldap_charray_free(specs); |
| 79 | ++ return LDAP_NO_MEMORY; |
| 80 | ++ } |
| 81 | ++ specs[i] = NULL; |
| 82 | ++ ldap_pvt_hex_unescape(ludp->lud_host); |
| 83 | + ludp->lud_next = *ludlist; |
| 84 | + *ludlist = ludp; |
| 85 | + } |
| 86 | + |
| 87 | + /* this should be an array of NULLs now */ |
| 88 | +- /* except entries starting with [ */ |
| 89 | + ldap_charray_free(specs); |
| 90 | + return LDAP_SUCCESS; |
| 91 | + } |
| 92 | +-- |
| 93 | +2.25.1 |
| 94 | + |
0 commit comments