1 #include <stdlib.h>
2 #include "ldap.h"
3 
scan_ldapsearchresultentry(const char * src,const char * max,struct SearchResultEntry * sre)4 size_t scan_ldapsearchresultentry(const char* src,const char* max,struct SearchResultEntry* sre) {
5   size_t res,tmp,oslen; /* outer sequence length */
6   struct PartialAttributeList** a=&sre->attributes;
7   *a=0;
8   if (!(res=scan_ldapstring(src,max,&sre->objectName))) goto error;
9   if (!(tmp=scan_asn1SEQUENCE(src+res,max,&oslen))) goto error;
10   res+=tmp;
11   if (src+res+oslen>max) goto error;
12   max=src+res+oslen;	/* we now may have a stronger limit */
13   while (src+res<max) {
14     struct string s;
15     struct AttributeDescriptionList* x;
16     size_t islen;
17     const char* nmax;
18     if (!(tmp=scan_asn1SEQUENCE(src+res,max,&islen))) goto error;
19     res+=tmp; nmax=src+res+islen; if (nmax>max) goto error;
20     if (!(tmp=scan_ldapstring(src+res,nmax,&s))) goto error;
21     if (!(*a=malloc(sizeof(struct PartialAttributeList)))) goto error;
22     (*a)->next=0; (*a)->values=0; (*a)->type=s;
23     res+=tmp;
24     if (!(tmp=scan_asn1SET(src+res,max,&islen))) goto error;
25     res+=tmp; if (src+res+islen!=nmax) goto error;
26     while (src+res<nmax) {
27       if (!(tmp=scan_ldapstring(src+res,max,&s))) goto error;
28       if (!(x=malloc(sizeof(struct AttributeDescriptionList)))) goto error;
29       x->a=s;
30       x->next=(*a)->values;
31       (*a)->values=x;
32       res+=tmp;
33     }
34     a=&(*a)->next;
35   }
36   *a=0;
37   return res;
38 error:
39   freepal(sre->attributes);
40   sre->attributes=0;
41   return 0;
42 }
43 
44