buglwIP - A Lightweight TCP/IP stack - Bugs: bug #41500, SMTP base64 patch

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #41500: SMTP base64 patch

Submitter:  Simon Goldschmidt <goldsimon>
Submitted:  Fri 07 Feb 2014 12:14:26 PM UTC
   
 
Category:  Contrib Severity:  3 - Normal
Item Group:  Faulty Behaviour Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Tue 02 Sep 2014 08:11:55 PM UTC, comment #2: 

Wouldn't "% 4" result in "& 3", not "% 3"?

Anyway, fixed like suggested in comment #1

Simon Goldschmidt <goldsimon>
Group administrator
Thu 26 Jun 2014 03:56:25 PM UTC, comment #1: 

I would go for a more elegant way (also attached as a patch file):
```
--- a/apps/smtp/smtp.c
+++ b/apps/smtp/smtp.c
@@ -808,9 +808,9 @@ smtp_base64_encode(char* target, size_t target_len, const ch
   size_t i;
   s8_t j;
   size_t target_idx = 0;
-  size_t longer = 3 - (source_len % 3);
+  size_t longer = (source_len % 3) ? (3 - (source_len % 3)) : 0;
   size_t source_len_b64 = source_len + longer;
-  size_t len = (((source_len_b64) * 4) / 3);
+  size_t len = (source_len_b64 / 3) * 4;
   u8_t x = 5;
   u8_t current = 0;
   LWIP_UNUSED_ARG(target_len);
```

I guess we can assume the compiler will be smart enough to not do the modulus calculation twice, and/or to do it as a simple &3.


(file #31623)

Sergio R. Caprile <scaprile>
Fri 07 Feb 2014 12:14:26 PM UTC, original submission:  

lwip-devel on 13-05-23:
"This generates working userpass auth strings. Tested with GMX, Lavabit, Aol, Plusnet, and Yahoo. With various username/password sizes.

--- C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/smtp/smtp.c    Mon Dec 17 19:03:22 2012
+++ C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/smtp/smtp - Copy.c    Thu May 23 08:51:16 2013
@@ -804,8 +804,8 @@
   s8_t j;
   size_t target_idx = 0;
   size_t longer = 3 - (source_len % 3);
-  size_t source_len_b64 = source_len + longer;
-  size_t len = (((source_len_b64) * 4) / 3);
+  size_t source_len_b64 = source_len + ((longer != 3) ? longer : 0);
+  size_t len = (((source_len_b64 / 3) * 4));
   u8_t x = 5;
   u8_t current = 0;
   LWIP_UNUSED_ARG(target_len);
@@ -824,7 +824,7 @@
       }
     }
   }
-  for (i = len - longer; i < len; i++) {
+  for (i = len - ((longer != 3) ? longer : 0); i < len; i++) {
     target[i] = '=';
   }
   return len;
"

Simon Goldschmidt <goldsimon>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #31623:  smtp2.patch added by scaprile (587B - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-09-02 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2014-06-26 scaprile Attached File- Added smtp2.patch, #31623

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code