Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ldap: fix OOM check #4467

Closed
wants to merge 1 commit into from

Conversation

@nico-abram
Copy link
Contributor

nico-abram commented Oct 5, 2019

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

This comment has been minimized.

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
Fixes #4261
@nico-abram nico-abram force-pushed the nico-abram:master branch from d3f8bca to dab5d27 Oct 5, 2019
@nico-abram

This comment has been minimized.

Copy link
Contributor Author

nico-abram commented Oct 5, 2019

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

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

@bagder
bagder approved these changes Oct 5, 2019
@jay jay closed this in 8bb3a95 Oct 5, 2019
@jay

This comment has been minimized.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.