]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ldap: do not base64 encode zero length string
authorDaniel Stenberg <daniel@haxx.se>
Thu, 18 Sep 2025 13:50:17 +0000 (15:50 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 18 Sep 2025 15:15:30 +0000 (17:15 +0200)
Reported-by: Joshua Rogers
Closes #18602

lib/ldap.c

index c66a56d7bb243abeacee1fd8bc0d3c26a251c748..4b232e2bb67633f8cdd353188b683f986de24e6c 100644 (file)
@@ -634,22 +634,9 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
           if((attr_len > 7) &&
              (strcmp(";binary", attr + (attr_len - 7)) == 0)) {
             /* Binary attribute, encode to base64. */
-            result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
-                                         &val_b64, &val_b64_sz);
-            if(result) {
-              ldap_value_free_len(vals);
-              FREE_ON_WINLDAP(attr);
-              ldap_memfree(attribute);
-              if(ber)
-                ber_free(ber, 0);
-
-              goto quit;
-            }
-
-            if(val_b64_sz > 0) {
-              result = Curl_client_write(data, CLIENTWRITE_BODY, val_b64,
-                                         val_b64_sz);
-              free(val_b64);
+            if(vals[i]->bv_len) {
+              result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
+                                           &val_b64, &val_b64_sz);
               if(result) {
                 ldap_value_free_len(vals);
                 FREE_ON_WINLDAP(attr);
@@ -659,6 +646,21 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
 
                 goto quit;
               }
+
+              if(val_b64_sz > 0) {
+                result = Curl_client_write(data, CLIENTWRITE_BODY, val_b64,
+                                           val_b64_sz);
+                free(val_b64);
+                if(result) {
+                  ldap_value_free_len(vals);
+                  FREE_ON_WINLDAP(attr);
+                  ldap_memfree(attribute);
+                  if(ber)
+                    ber_free(ber, 0);
+
+                  goto quit;
+                }
+              }
             }
           }
           else {