]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sendf: accept zero-length data in Curl_client_write()
authorPatrick Monnerat <patrick@monnerat.net>
Mon, 25 Oct 2021 11:54:57 +0000 (13:54 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 25 Oct 2021 21:33:41 +0000 (23:33 +0200)
Historically, Curl_client_write() used a length value of 0 as a marker
for a null-terminated data string. This feature has been removed in
commit f4b85d2. To detect leftover uses of the feature, a DEBUGASSERT
statement rejecting a length with value 0 was introduced, effectively
precluding use of this function with zero-length data.

The current commit removes the DEBUGASSERT and makes the function to
return immediately if length is 0.

A direct effect is to fix trying to output a zero-length distinguished
name in openldap.

Another DEBUGASSERT statement is also rephrased for better readability.

Closes #7898

lib/sendf.c

index 14ca84bfe5bf5dd634f13ebe7bb725c40a0dfe47..bcfa27a501ff4c17ed8f5eaa1343b53dd72dab2d 100644 (file)
@@ -608,7 +608,7 @@ static CURLcode chop_write(struct Curl_easy *data,
 /* Curl_client_write() sends data to the write callback(s)
 
    The bit pattern defines to what "streams" to write to. Body and/or header.
-   The defines are in sendf.h of course. "len" is not allowed to be 0.
+   The defines are in sendf.h of course.
 
    If CURL_DO_LINEEND_CONV is enabled, data is converted IN PLACE to the
    local character encoding.  This is a problem and should be changed in
@@ -621,8 +621,10 @@ CURLcode Curl_client_write(struct Curl_easy *data,
 {
   struct connectdata *conn = data->conn;
 
-  DEBUGASSERT(len);
-  DEBUGASSERT(type <= 3);
+  DEBUGASSERT(!(type & ~CLIENTWRITE_BOTH));
+
+  if(!len)
+    return CURLE_OK;
 
   /* FTP data may need conversion. */
   if((type & CLIENTWRITE_BODY) &&