annotate src/libstrfunc.c @ 42:7a97f50c39c5 stable-0-5-12 **FUNKY**

security fix for potential buffer overrun in lz decompress
author carl
date Tue, 02 Oct 2007 16:10:36 -0700
parents 6fe121a971c9
children f6db1f060a95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2 /* Taken from LibStrfunc v7.3 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 #include <ctype.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 #include "libstrfunc.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 static unsigned char _sf_uc_ib[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/==";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 char *
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 base64_encode(void *data, size_t size) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 char *output;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 register char *ou;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 register unsigned char *p=(unsigned char *)data;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 #ifdef __LINUX__
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18 register void * dte = ((char*)data + size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 #ifndef __LINUX__
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 register void * dte = (void*)((char*)data + size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 //register void *dte=data + size;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 register int nc=0;
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
26
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
27 if ( data == NULL || size == 0 )
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
28 return NULL;
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
29
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
30 ou=output=(char *)malloc(size / 3 * 4 + (size / 57) + 5);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 if(!output)
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
32 return NULL;
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
33
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 while((char *)dte - (char *)p >= 3) {
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
35 unsigned char x = p[0];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
36 unsigned char y = p[1];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
37 unsigned char z = p[2];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
38 ou[0] = _sf_uc_ib[ x >> 2 ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
39 ou[1] = _sf_uc_ib[ ((x & 0x03) << 4) | (y >> 4) ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
40 ou[2] = _sf_uc_ib[ ((y & 0x0F) << 2) | (z >> 6) ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
41 ou[3] = _sf_uc_ib[ z & 0x3F ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
42 p+=3;
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
43 ou+=4;
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
44 nc+=4;
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
45 if(!(nc % 76)) *ou++='\n';
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 };
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 if((char *)dte - (char *)p == 2) {
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
48 *ou++ = _sf_uc_ib[ *p >> 2 ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
49 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) | (p[1] >> 4) ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
50 *ou++ = _sf_uc_ib[ ((p[1] & 0x0F) << 2) ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
51 *ou++ = '=';
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 } else if((char *)dte - (char *)p == 1) {
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
53 *ou++ = _sf_uc_ib[ *p >> 2 ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
54 *ou++ = _sf_uc_ib[ ((*p & 0x03) << 4) ];
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
55 *ou++ = '=';
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
56 *ou++ = '=';
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57 };
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
58
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 *ou=0;
36
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
60
6fe121a971c9 valgrind fixes
carl
parents: 31
diff changeset
61 return output;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
62 };
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63