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
Closed

ldap: fix OOM check #4467

wants to merge 1 commit into from

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