>Number:         3411
>Category:       other
>Synopsis:       [PATCH] ap_uuencode() has number of bugs
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Tue Nov 17 19:10:00 PST 1998
>Last-Modified:
>Originator:     [EMAIL PROTECTED]
>Organization:
apache
>Release:        1.3.*
>Environment:
all
>Description:
ap_uuencode() in main/util.c has a few problems:

1) the trailing padding ('='s) is completely wrong (always adds two '='s).
2) encoding 8 bit characters on a machine with signed char may produce
   incorrect results (one masking operation was forgotten)
3) EBCDIC handling wasn't done

The attached patch solves these problems (though the EBCDIC part isn't tested).
It doesn't solve the problem of the function having the wrong name, though
(i.e. uuencoding and base64 encoding are two decidedly different encodings).

Note I marked this "non-critical" only because no standard modules seem to use
this function.
>How-To-Repeat:
1) base64-encoding "bla" should yield "Ymxh", but yields "Ym==" instead.
2) base64-encoding "�hm" should yield "5Ght", but yields something unprintable 
instead.
3) can't test this...
>Fix:
Diff for apache-1.3.4-dev:

--- main/util.c.orig    Fri Nov  6 18:12:27 1998
+++ main/util.c Tue Nov 17 17:30:48 1998
@@ -1749,18 +1749,44 @@
 { 
     int i, len = strlen(string); 
     char *p; 
-    char *encoded = (char *) ap_pcalloc(a, (len+2) / 3 * 4); 
+    char *encoded = (char *) ap_palloc(a, (len+2) / 3 * 4); 
  
     p = encoded; 
-    for (i = 0; i < len; i += 3) { 
-        *p++ = basis_64[string[i] >> 2]; 
+#ifndef CHARSET_EBCDIC
+    for (i = 0; i < len-2; i += 3) { 
+        *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
         *p++ = basis_64[((string[i] & 0x3) << 4) | ((int) (string[i + 1] & 
0xF0) >> 4)]; 
         *p++ = basis_64[((string[i + 1] & 0xF) << 2) | ((int) (string[i + 2] & 
0xC0) >> 6)]; 
         *p++ = basis_64[string[i + 2] & 0x3F]; 
     } 
-    *p-- = '\0'; 
-    *p-- = '='; 
-    *p-- = '='; 
+    if (i < len) {
+        *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
+       *p++ = basis_64[((string[i] & 0x3) << 4) | ((int) (string[i + 1] & 
0xF0) >> 4)]; 
+       if (i == (len-2))
+           *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; 
+       else
+           *p++ = '='; 
+       *p++ = '='; 
+    }
+#else /*CHARSET_EBCDIC*/
+    for (i = 0; i < len-2; i += 3) { 
+        *p++ = os_toebcdic[basis_64[(os_toascii[string[i]] >> 2) & 0x3F]]; 
+        *p++ = os_toebcdic[basis_64[((os_toascii[string[i]] & 0x3) << 4) | 
((int) (os_toascii[string[i + 1]] & 0xF0) >> 4)]]; 
+        *p++ = os_toebcdic[basis_64[((os_toascii[string[i + 1]] & 0xF) << 2) | 
((int) (os_toascii[string[i + 2]] & 0xC0) >> 6)]]; 
+        *p++ = os_toebcdic[basis_64[os_toascii[string[i + 2]] & 0x3F]]; 
+    } 
+    if (i < len) {
+        *p++ = os_toebcdic[basis_64[(os_toascii[string[i]] >> 2) & 0x3F]]; 
+       *p++ = os_toebcdic[basis_64[((os_toascii[string[i]] & 0x3) << 4) | 
((int) (os_toascii[string[i + 1]] & 0xF0) >> 4)]]; 
+       if (i == (len-2))
+           *p++ = os_toebcdic[basis_64[((os_toascii[string[i + 1]] & 0xF) << 
2)]]; 
+       else
+           *p++ = '='; 
+       *p++ = '='; 
+    }
+#endif /*CHARSET_EBCDIC*/
+
+    *p = '\0'; 
     return encoded; 
 } 
 
>Audit-Trail:
>Unformatted:
[In order for any reply to be added to the PR database, ]
[you need to include <[EMAIL PROTECTED]> in the Cc line ]
[and leave the subject line UNCHANGED.  This is not done]
[automatically because of the potential for mail loops. ]
[If you do not include this Cc, your reply may be ig-   ]
[nored unless you are responding to an explicit request ]
[from a developer.                                      ]
[Reply only with text; DO NOT SEND ATTACHMENTS!         ]



Reply via email to