test suite work
This commit is contained in:
27
Makefile
27
Makefile
@@ -123,13 +123,6 @@ test/%: test/%.c asn1.a ldap.a
|
||||
$(DIET) $(CC) $(CFLAGS) -o $@ $^ ldap.a asn1.a -lowfat $(LIBS)
|
||||
|
||||
.PHONY: clean tar
|
||||
clean:
|
||||
rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient \
|
||||
parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \
|
||||
dumpidx idx2ldif md5password ldapdelete dumpacls asn1dump acl \
|
||||
mysql2ldif x \
|
||||
*.da *.bbg *.bb *.gcov gmon.out *.gcda *.gcno test/bind bind/ebind
|
||||
|
||||
tar: clean
|
||||
cd ..; tar cvvf tinyldap.tar.bz2 tinyldap --use=bzip2 --exclude capture --exclude CVS --exclude exp.ldif --exclude polyp* --exclude rfc*
|
||||
|
||||
@@ -231,3 +224,23 @@ tls_cipherprio.o: tls_cipherprio.c
|
||||
tls_connect.o: tls_connect.c tinytls.h asn1.h
|
||||
tls_doread.o: tls_doread.c tinytls.h asn1.h
|
||||
tls_dowrite.o: tls_dowrite.c tinytls.h asn1.h
|
||||
|
||||
WITH_UNITTEST = $(shell grep -l UNITTEST *.c)
|
||||
UNITTEST_BIN = $(patsubst %.c, test/%, $(WITH_UNITTEST))
|
||||
|
||||
test/%: %.c
|
||||
gcc --coverage -DUNITTEST -o $@ $^ -I.
|
||||
$@
|
||||
|
||||
check: $(UNITTEST_BIN)
|
||||
echo done
|
||||
|
||||
clean:
|
||||
rm -f t t[1-9] *.[ao] bindrequest tinyldap ldapclient \
|
||||
parse tinyldap_standalone tinyldap_debug ldapclient_str addindex \
|
||||
dumpidx idx2ldif md5password ldapdelete dumpacls asn1dump acl \
|
||||
mysql2ldif x \
|
||||
*.da *.bbg *.bb *.gcov gmon.out *.gcda *.gcno test/bind bind/ebind \
|
||||
$(UNITTEST_BIN) test/*.gcda test/*.gcno
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,8 @@ size_t fmt_asn1intpayload(char* dest,unsigned long l) {
|
||||
/* need to store big endian */
|
||||
/* n is the number of bits to shift right for the next octet */
|
||||
for (i=0, n=(needed-1)*8; i<needed; ++i, n-=8)
|
||||
dest[i]=(l >> n);
|
||||
// shifting by more bits than are in the type is undefined behavior :(
|
||||
dest[i]= (n == sizeof(l)*8) ? 0 : (l >> n);
|
||||
}
|
||||
return needed;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ static size_t sintpayloadlen(signed long l) {
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t fmt_asn1intpayload(char* dest,unsigned long l) {
|
||||
size_t fmt_asn1sintpayload(char* dest,signed long l) {
|
||||
size_t needed=sintpayloadlen(l);
|
||||
if (dest) {
|
||||
size_t i,n;
|
||||
@@ -68,7 +68,8 @@ int main() {
|
||||
assert(sintpayloadlen(0x7f)==1);
|
||||
assert(sintpayloadlen(0x80)==2);
|
||||
assert(sintpayloadlen(0x80000000)==5);
|
||||
if (sizeof(long)==8) assert(sintpayloadlen(0x8000000000000000ul)==9);
|
||||
if (sizeof(long)==8) assert(sintpayloadlen(0x8000000000000000ul)==8);
|
||||
if (sizeof(long)==8) assert(sintpayloadlen(0x0083456789abcdeful)==8);
|
||||
|
||||
char buf[100];
|
||||
buf[1]='!';
|
||||
|
||||
@@ -16,7 +16,7 @@ size_t scan_asn1BITSTRING(const char* src,const char* max,const char** s,size_t*
|
||||
if (*l==1 && **s)
|
||||
return 0;
|
||||
/* now check if the unused bits are 0 */
|
||||
lastbyte=(*s)[*l+1];
|
||||
lastbyte=(*s)[*l-1];
|
||||
if (lastbyte & (0xff >> (8-**s)))
|
||||
return 0;
|
||||
*l=(*l-1)*8-(unsigned char)(**s);
|
||||
@@ -40,8 +40,11 @@ int main() {
|
||||
char buf[100];
|
||||
const char* s;
|
||||
size_t l;
|
||||
strcpy(buf,"\x03\x02\x07\x01"); // 0x03 = UNIVERSAL PRIMITIVE BIT_STRING, 0x02 = length 5, 0x07 = unused bits in last octet, 0x01 = 1
|
||||
assert(scan_asn1BITSTRING(buf,buf+4,&s,&l)==4 && s==buf+2 && l==2);
|
||||
strcpy(buf,"\x03\x04\x06\x6e\x5d\xc0");
|
||||
size_t r = scan_asn1BITSTRING(buf, buf+6, &s, &l);
|
||||
assert(r==6 && s==buf+3 && l==18);
|
||||
strcpy(buf,"\x03\x02\x07\x80"); // 0x03 = UNIVERSAL PRIMITIVE BIT_STRING, 0x02 = length 2, 0x07 = unused bits in last octet, 0x80 = 1
|
||||
assert(scan_asn1BITSTRING(buf,buf+4,&s,&l)==4 && s==buf+3 && l==1);
|
||||
assert(scan_asn1BITSTRING(buf,buf+3,&s,&l)==0); // short input, make scan_asn1string fail
|
||||
buf[0]=0x13; // 0x13 = UNIVERSAL PRIMITIVE PrintableString
|
||||
assert(scan_asn1BITSTRING(buf,buf+4,&s,&l)==0); // scan_asn1string succeeds but line 9 fails
|
||||
@@ -50,10 +53,10 @@ int main() {
|
||||
buf[2]=7; buf[1]=0;
|
||||
assert(scan_asn1BITSTRING(buf,buf+4,&s,&l)==0); // scan_asn1string succeeds but line 11 fails
|
||||
strcpy(buf,"\x03\x01\x00"); // length 0 bit string
|
||||
assert(scan_asn1BITSTRING(buf,buf+3,&s,&l)==3 && s==buf+2 && l==1);
|
||||
assert(scan_asn1BITSTRING(buf,buf+3,&s,&l)==3 && s==buf+3 && l==0);
|
||||
buf[2]=1;
|
||||
assert(scan_asn1BITSTRING(buf,buf+3,&s,&l)==0); // length 0 but says it has unused bits, return 0 in line 17
|
||||
strcpy(buf,"\x03\x02\x07\x81"); // 0x03 = UNIVERSAL PRIMITIVE BIT_STRING, 0x02 = length 5, 0x07 = unused bits in last octet, 0x01 = 1
|
||||
strcpy(buf,"\x03\x02\x07\x81"); // 0x03 = UNIVERSAL PRIMITIVE BIT_STRING, 0x02 = length 2, 0x07 = unused bits in last octet, 0x81 = invalid
|
||||
assert(scan_asn1BITSTRING(buf,buf+4,&s,&l)==0); // unused bits not 0, return 0 in line 21
|
||||
// we only care for 100% coverage of this file, the others have their own unit tests */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user