aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGraeme Lunt <graeme.lunt@smhs.co.uk>2007-07-14 09:12:38 +0000
committerGraeme Lunt <graeme.lunt@smhs.co.uk>2007-07-14 09:12:38 +0000
commitcf24e2c10447242730f20f8d8c6c2a74e095feb7 (patch)
tree140916e3736980e8c75f4b9534ff185d92f58c2c
parentfc842e9933fc267912074bfea66f2e996d37d157 (diff)
Allow the base64 decoding to cope with lines broken with \r\n.
svn path=/trunk/; revision=22309
-rw-r--r--epan/base64.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/epan/base64.c b/epan/base64.c
index c3bc53faa2..b390947f35 100644
--- a/epan/base64.c
+++ b/epan/base64.c
@@ -35,28 +35,35 @@
size_t epan_base64_decode(char *s)
{
- static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+ static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\r\n";
int bit_offset, byte_offset, idx, i, n;
unsigned char *d = (unsigned char *)s;
char *p;
+ int cr_idx;
+
+ /* we will allow CR and LF - but ignore them */
+ cr_idx = strchr(b64, '\r') - b64;
n=i=0;
while (*s && (p=strchr(b64, *s))) {
idx = (int)(p - b64);
- byte_offset = (i*6)/8;
- bit_offset = (i*6)%8;
- d[byte_offset] &= ~((1<<(8-bit_offset))-1);
- if (bit_offset < 3) {
- d[byte_offset] |= (idx << (2-bit_offset));
- n = byte_offset+1;
- } else {
- d[byte_offset] |= (idx >> (bit_offset-2));
- d[byte_offset+1] = 0;
- d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
- n = byte_offset+2;
+ if(idx < cr_idx) {
+ byte_offset = (i*6)/8;
+ bit_offset = (i*6)%8;
+ d[byte_offset] &= ~((1<<(8-bit_offset))-1);
+ if (bit_offset < 3) {
+ d[byte_offset] |= (idx << (2-bit_offset));
+ n = byte_offset+1;
+ } else {
+ d[byte_offset] |= (idx >> (bit_offset-2));
+ d[byte_offset+1] = 0;
+ d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
+ n = byte_offset+2;
+ }
+ i++;
}
- s++; i++;
+ s++;
}
return n;