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

Submitted by:  Simon Goldschmidt <goldsimon>
Submitted on:  Fri 07 Feb 2014 12:14:26 PM UTC  
 
Category: ContribSeverity: 3 - Normal
Item Group: Faulty BehaviourStatus: Fixed
Privacy: PublicAssigned to: Simon Goldschmidt <goldsimon>
Open/Closed: ClosedPlanned 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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.

 

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
  • -unavailable- added by goldsimon (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 02 Sep 2014 08:11:55 PM UTCgoldsimonStatusNone=>Fixed
      Assigned toNone=>goldsimon
      Open/ClosedOpen=>Closed
    Thu 26 Jun 2014 03:56:25 PM UTCscaprileAttached File-=>Added smtp2.patch, #31623

    Back to the top


    Powered by Savane 3.1-cleanup1