libplumb: allow attributes larger than 4096, set some malloc tags

This commit is contained in:
mischief 2018-05-01 12:47:26 -07:00
parent e87ca8d976
commit d05b90f300

View file

@ -76,15 +76,21 @@ quote(char *s, char *buf, char *bufe)
char*
plumbpackattr(Plumbattr *attr)
{
int n;
int n, l;
Plumbattr *a;
char *s, *t, *buf, *bufe;
if(attr == nil)
return nil;
if((buf = malloc(4096)) == nil)
n = 0;
for(a=attr; a!=nil; a=a->next){
l = Strlen(a->value);
if(l > n)
n = l;
}
if((buf = malloc(n*2+3)) == nil)
return nil;
bufe = buf + 4096;
bufe = buf + n*2+3;
n = 0;
for(a=attr; a!=nil; a=a->next)
n += Strlen(a->name) + 1 + Strlen(quote(a->value, buf, bufe)) + 1;
@ -221,9 +227,11 @@ plumbunpackattr(char *p)
char *q, *v, *buf, *bufe;
int c, quoting;
if((buf = malloc(4096)) == nil)
c = strlen(p) + 1;
if((buf = malloc(c)) == nil)
return nil;
bufe = buf + 4096;
bufe = buf + c;
attr = prev = nil;
while(*p!='\0' && *p!='\n'){
while(*p==' ' || *p=='\t')
@ -340,6 +348,7 @@ plumbunpackpartial(char *buf, int n, int *morep)
m = malloc(sizeof(Plumbmsg));
if(m == nil)
return nil;
setmalloctag(m, getcallerpc(&buf));
memset(m, 0, sizeof(Plumbmsg));
if(morep != nil)
*morep = 0;
@ -384,7 +393,11 @@ plumbunpackpartial(char *buf, int n, int *morep)
Plumbmsg*
plumbunpack(char *buf, int n)
{
return plumbunpackpartial(buf, n, nil);
Plumbmsg *m;
m = plumbunpackpartial(buf, n, nil);
if(m != nil)
setmalloctag(m, getcallerpc(&buf));
return m;
}
Plumbmsg*