Skip to content

ldap: fix OOM check#4467

Closed
nico-abram wants to merge 1 commit intocurl:masterfrom
nico-abram:master
Closed

ldap: fix OOM check#4467
nico-abram wants to merge 1 commit intocurl:masterfrom
nico-abram:master

Conversation

@nico-abram
Copy link
Contributor

Should Fix #4261

This just applies the changes described in #4261 (comment)

I tested before and after on windows 7 64 bit, it gave me the OOM message before, and the expected output after the change.

@bagder
Copy link
Member

bagder commented Oct 5, 2019

Thanks! I just find it a little bit weird to strdup() the pointer if it is NULL and check for NULL after the fact. How about instead doing something like below, to make it a little more readable?

--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -845,11 +845,11 @@ static int _ldap_url_parse2(const struct connectdata *conn, LDAPURLDesc *ludp)
 {
   int rc = LDAP_SUCCESS;
   char *path;
   char *query;
   char *p;
-  char *q;
+  char *q = NULL;
   size_t i;
 
   if(!conn->data ||
      !conn->data->state.up.path ||
      conn->data->state.up.path[0] != '/' ||
@@ -863,15 +863,17 @@ static int _ldap_url_parse2(const struct connectdata *conn, LDAPURLDesc *ludp)
   /* Duplicate the path */
   p = path = strdup(conn->data->state.up.path + 1);
   if(!path)
     return LDAP_NO_MEMORY;
 
-  /* Duplicate the query */
-  q = query = strdup(conn->data->state.up.query);
-  if(!query) {
-    free(path);
-    return LDAP_NO_MEMORY;
+  /* Duplicate the query if present */
+  if(conn->data->state.up.query) {
+    q = query = strdup(conn->data->state.up.query);
+    if(!query) {
+      free(path);
+      return LDAP_NO_MEMORY;
+    }
   }
 
   /* Parse the DN (Distinguished Name) */
   if(*p) {
     char *dn = p;

@bagder bagder added the LDAP label Oct 5, 2019
@nico-abram
Copy link
Contributor Author

You're absolutely right, thank you for the review!

I force pushed the changes so as to not make it two commits.

@jay jay closed this in 8bb3a95 Oct 5, 2019
@jay
Copy link
Member

jay commented Oct 5, 2019

Thanks. I modified the commit to say this is a partial fix for #4261 which I think is two bugs, and this fixes one of them. Also I changed add init query NULL because later in cleanup there's free(query).

@lock lock bot locked as resolved and limited conversation to collaborators Jan 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

LDAP on windows not working

3 participants