components/curl/patches/006-CVE-2013-0249.patch
changeset 2151 8977d970976a
parent 2150 1acc968ac0d9
child 2152 1cea7a430dd7
equal deleted inserted replaced
2150:1acc968ac0d9 2151:8977d970976a
     1 From ee45a34907ffeb5fd95b0513040d8491d565b663 Mon Sep 17 00:00:00 2001
       
     2 From: Eldar Zaitov <[email protected]>
       
     3 Date: Wed, 30 Jan 2013 23:22:27 +0100
       
     4 Subject: [PATCH] Curl_sasl_create_digest_md5_message: fix buffer overflow
       
     5 
       
     6 When negotiating SASL DIGEST-MD5 authentication, the function
       
     7 Curl_sasl_create_digest_md5_message() uses the data provided from the
       
     8 server without doing the proper length checks and that data is then
       
     9 appended to a local fixed-size buffer on the stack.
       
    10 
       
    11 This vulnerability can be exploited by someone who is in control of a
       
    12 server that a libcurl based program is accessing with POP3, SMTP or
       
    13 IMAP. For applications that accept user provided URLs, it is also
       
    14 thinkable that a malicious user would feed an application with a URL to
       
    15 a server hosting code targetting this flaw.
       
    16 
       
    17 Bug: http://curl.haxx.se/docs/adv_20130206.html
       
    18 
       
    19 (Note that these changes need to be applied to similar code in 
       
    20  .../lib/smtp.c for curl version 7.26.0)
       
    21 
       
    22 --- lib/smtp.c.orig	2013-02-05 08:06:03.823585006 -0800
       
    23 +++ lib/smtp.c	2013-02-05 08:12:38.007595100 -0800
       
    24 @@ -879,7 +879,7 @@
       
    25    char cnonce[]     = "12345678"; /* will be changed */
       
    26    char method[]     = "AUTHENTICATE";
       
    27    char qop[]        = "auth";
       
    28 -  char uri[128]     = "smtp/";
       
    29 +  char uri[128];
       
    30    char response[512];
       
    31  
       
    32    (void)instate; /* no use for this yet */
       
    33 @@ -963,8 +963,8 @@
       
    34    for(i = 0; i < MD5_DIGEST_LEN; i++)
       
    35      snprintf(&HA1_hex[2 * i], 3, "%02x", digest[i]);
       
    36  
       
    37 -  /* Orepare URL string, append realm to the protocol */
       
    38 -  strcat(uri, realm);
       
    39 +  /* Prepare URL string, append realm to the protocol */
       
    40 +  snprintf(uri, sizeof(uri), "smtp/%s", realm);
       
    41  
       
    42    /* Calculate H(A2) */
       
    43    ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
       
    44 @@ -1008,20 +1008,11 @@
       
    45    for(i = 0; i < MD5_DIGEST_LEN; i++)
       
    46      snprintf(&resp_hash_hex[2 * i], 3, "%02x", digest[i]);
       
    47  
       
    48 -  strcpy(response, "username=\"");
       
    49 -  strcat(response, conn->user);
       
    50 -  strcat(response, "\",realm=\"");
       
    51 -  strcat(response, realm);
       
    52 -  strcat(response, "\",nonce=\"");
       
    53 -  strcat(response, nonce);
       
    54 -  strcat(response, "\",cnonce=\"");
       
    55 -  strcat(response, cnonce);
       
    56 -  strcat(response, "\",nc=");
       
    57 -  strcat(response, nonceCount);
       
    58 -  strcat(response, ",digest-uri=\"");
       
    59 -  strcat(response, uri);
       
    60 -  strcat(response, "\",response=");
       
    61 -  strcat(response, resp_hash_hex);
       
    62 +  snprintf(response, sizeof(response),
       
    63 +           "username=\"%s\",realm=\"%s\",nonce=\"%s\","
       
    64 +           "cnonce=\"%s\",nc=\"%s\",digest-uri=\"%s\",response=%s",
       
    65 +           conn->user, realm, nonce,
       
    66 +           cnonce, nonceCount, uri, resp_hash_hex);
       
    67  
       
    68    /* Encode it to base64 and send it */
       
    69    result = Curl_base64_encode(data, response, 0, &rplyb64, &len);