On dom, feb 10, 2013 at 05:14:16 +0000, Steve Holme wrote:
> My only comment if you wanted to reduce code a little and save the amount of
> work snprintf() has to do is to replace the service variable and the
> following line:
> 
> +  snprintf(uri, sizeof(uri), "%s/%s", service, realm);
> 
> With:
> 
> +  snprintf(uri, sizeof(uri), "smtp/%s", realm);

On dom, feb 10, 2013 at 06:03:40 +0100, Daniel Stenberg wrote:
> If I would make the patch, I would not introduce a new local array
> named 'service'. I would just have that first snprintf() use "smtp"
> instead of the first %s. But that's just a matter of style and
> taste, not a technical issue.

I have updated my patch to not use a separate service[] (for the curious, see
attachment). Btw, to anyone who may need it, feel free to use it.

Thanks to both!

Cheers

-- 
perl -E '$_=q;$/= @{[@_]};and s;\S+;<inidehG ordnasselA>;eg;say~~reverse'
Description: Fix buffer overflow in SMTP DIGEST-MD5 negotiation
 When negotiating SMTP DIGEST-MD5 authentication, the function
 smtp_state_authdigest_resp() uses the data provided from the
 server without doing the proper length checks and that data is then
 appended to a local fixed-size buffer on the stack.
Origin: vendor, adapted from http://curl.haxx.se/curl-sasl.patch
Bug: http://curl.haxx.se/docs/adv_20130206.html
Bug-Debian: http://bugs.debian.org/700002
Forwarded: not-needed
Author: Alessandro Ghedini <[email protected]>
Last-Update: 2013-02-10

--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -879,7 +879,7 @@
   char cnonce[]     = "12345678"; /* will be changed */
   char method[]     = "AUTHENTICATE";
   char qop[]        = "auth";
-  char uri[128]     = "smtp/";
+  char uri[128];
   char response[512];
 
   (void)instate; /* no use for this yet */
@@ -963,8 +963,8 @@
   for(i = 0; i < MD5_DIGEST_LEN; i++)
     snprintf(&HA1_hex[2 * i], 3, "%02x", digest[i]);
 
-  /* Orepare URL string, append realm to the protocol */
-  strcat(uri, realm);
+  /* Prepare the URL string */
+  snprintf(uri, sizeof(uri), "smtp/%s", realm);
 
   /* Calculate H(A2) */
   ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
@@ -1008,20 +1008,11 @@
   for(i = 0; i < MD5_DIGEST_LEN; i++)
     snprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]);
 
-  strcpy(response, "username=\"");
-  strcat(response, conn->user);
-  strcat(response, "\",realm=\"");
-  strcat(response, realm);
-  strcat(response, "\",nonce=\"");
-  strcat(response, nonce);
-  strcat(response, "\",cnonce=\"");
-  strcat(response, cnonce);
-  strcat(response, "\",nc=");
-  strcat(response, nonceCount);
-  strcat(response, ",digest-uri=\"");
-  strcat(response, uri);
-  strcat(response, "\",response=");
-  strcat(response, resp_hash_hex);
+  snprintf(response, sizeof(response),
+           "username=\"%s\",realm=\"%s\",nonce=\"%s\","
+           "cnonce=\"%s\",nc=\"%s\",digest-uri=\"%s\",response=%s",
+           conn->user, realm, nonce,
+           cnonce, nonceCount, uri, resp_hash_hex);
 
   /* Encode it to base64 and send it */
   result = Curl_base64_encode(data, response, 0, &rplyb64, &len);

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to