try not to leak memory in case of parse error
This commit is contained in:
1
Makefile
1
Makefile
@@ -20,6 +20,7 @@ fmt_ldapresult.o fmt_ldappal.o fmt_ldapadl.o fmt_ldapava.o \
|
||||
fmt_ldapsearchfilter.o fmt_ldapsearchrequest.o matchstring.o \
|
||||
matchprefix.o byte_case_diff.o matchcasestring.o matchcaseprefix.o \
|
||||
scan_ldapmodifyrequest.o bstrlen.o bstrfirst.o bstrstart.o \
|
||||
free_ldapadl.o free_ldappal.o free_ldapsearchfilter.o
|
||||
|
||||
ldif.a: ldif_parse.o ldap_match.o ldap_match_mapped.o
|
||||
|
||||
|
||||
10
free_ldapadl.c
Normal file
10
free_ldapadl.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
#include "ldap.h"
|
||||
|
||||
void free_ldapadl(struct AttributeDescriptionList* a) {
|
||||
while (a) {
|
||||
struct AttributeDescriptionList* tmp=a->next;
|
||||
free(a); a=tmp;
|
||||
}
|
||||
}
|
||||
|
||||
11
free_ldappal.c
Normal file
11
free_ldappal.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdlib.h>
|
||||
#include "ldap.h"
|
||||
|
||||
void free_ldappal(struct PartialAttributeList* a) {
|
||||
while (a) {
|
||||
struct PartialAttributeList* tmp=a->next;
|
||||
free_ldapadl(a->values);
|
||||
free(a); a=tmp;
|
||||
}
|
||||
}
|
||||
|
||||
23
free_ldapsearchfilter.c
Normal file
23
free_ldapsearchfilter.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdlib.h>
|
||||
#include "asn1.h"
|
||||
#include "ldap.h"
|
||||
|
||||
void free_ldapsearchfilter(struct Filter* f) {
|
||||
while (f) {
|
||||
struct Filter* tmp=f->next;
|
||||
switch (f->type) {
|
||||
case AND: case OR: case NOT:
|
||||
free_ldapsearchfilter(f->x);
|
||||
break;
|
||||
case SUBSTRING:
|
||||
while (f->substrings) {
|
||||
struct Substring* s=f->substrings->next;
|
||||
free(f->substrings);
|
||||
f->substrings=s;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(f); f=tmp;
|
||||
}
|
||||
}
|
||||
9
ldap.h
9
ldap.h
@@ -130,4 +130,13 @@ int fmt_ldapmodifyrequest(char* dest,struct ModifyRequest* m);
|
||||
#define fmt_ldapbindresponse(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e)
|
||||
#define fmt_ldapsearchresultdone(a,b,c,d,e) fmt_ldapresult(a,b,c,d,e)
|
||||
|
||||
void free_ldapadl(struct AttributeDescriptionList* a);
|
||||
void free_ldappal(struct PartialAttributeList* a);
|
||||
void free_ldapsearchfilter(struct Filter* f);
|
||||
/* does not free s itself */
|
||||
void free_ldapsearchrequest(struct SearchRequest* s);
|
||||
/* does not free m itself */
|
||||
void free_ldapmodifyrequest(struct ModifyRequest* m);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include <md5.h>
|
||||
#include <string.h>
|
||||
#include "buffer.h"
|
||||
#include "str.h"
|
||||
#include "textcode.h"
|
||||
|
||||
@@ -21,6 +21,7 @@ int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest*
|
||||
int res,tmp;
|
||||
long oslen; /* outer sequence length */
|
||||
struct Modification* last=0;
|
||||
m->m.next=0;
|
||||
if (!(res=scan_ldapstring(src,max,&m->object))) goto error;
|
||||
if (!(tmp=scan_asn1SEQUENCE(src+res,max,&oslen))) goto error;
|
||||
res+=tmp;
|
||||
@@ -73,5 +74,19 @@ int scan_ldapmodifyrequest(const char* src,const char* max,struct ModifyRequest*
|
||||
} while (src+res<max);
|
||||
return res;
|
||||
error:
|
||||
free_ldapmodifyrequest(m);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_mod(struct Modification* m) {
|
||||
while (m) {
|
||||
struct Modification* tmp=m->next;
|
||||
free(m);
|
||||
m=tmp;
|
||||
}
|
||||
}
|
||||
|
||||
void free_ldapmodifyrequest(struct ModifyRequest* m) {
|
||||
free_ldapadl(m->m.vals.next);
|
||||
free_mod(m->m.next);
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ int scan_ldapsearchfilter(const char* src,const char* max,struct Filter** f) {
|
||||
}
|
||||
return res;
|
||||
error:
|
||||
freefilter((*f));
|
||||
free_ldapsearchfilter(*f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ int scan_ldapsearchrequest(const char* src,const char* max,
|
||||
struct SearchRequest* s) {
|
||||
int res,tmp;
|
||||
unsigned long etmp;
|
||||
s->attributes=0;
|
||||
s->filter=0;
|
||||
if (!(res=scan_ldapstring(src,max,&s->baseObject))) goto error;
|
||||
if (!(tmp=scan_asn1ENUMERATED(src+res,max,&etmp))) goto error;
|
||||
if (etmp>2) goto error; s->scope=etmp; res+=tmp;
|
||||
@@ -40,5 +42,11 @@ int scan_ldapsearchrequest(const char* src,const char* max,
|
||||
return res;
|
||||
}
|
||||
error:
|
||||
free_ldapsearchrequest(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_ldapsearchrequest(struct SearchRequest* s) {
|
||||
free_ldapadl(s->attributes->next);
|
||||
free_ldapsearchfilter(s->filter);
|
||||
}
|
||||
|
||||
@@ -514,6 +514,7 @@ add_attribute:
|
||||
fmt_ldapsearchresultentry(buf+tmp,&sre);
|
||||
write(out,buf,l+tmp);
|
||||
}
|
||||
free_ldappal(sre.attributes);
|
||||
}
|
||||
|
||||
int handle(int in,int out) {
|
||||
@@ -624,9 +625,9 @@ authfailure:
|
||||
buffer_putsflush(buffer_2,"wrong password, bind failed!\n");
|
||||
goto authfailure;
|
||||
}
|
||||
found:
|
||||
}
|
||||
}
|
||||
found:
|
||||
{
|
||||
char outbuf[1024];
|
||||
int s=100;
|
||||
@@ -709,6 +710,7 @@ found:
|
||||
x+=j*8;
|
||||
}
|
||||
}
|
||||
free_ldapsearchrequest(&sr);
|
||||
} else {
|
||||
buffer_putsflush(buffer_2,"couldn't parse search request!\n");
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user