libdraw: check fontchar count in openmemsubfont() and readsubfont()

This commit is contained in:
cinap_lenrek 2015-02-24 03:30:21 +01:00
parent 5f8cacd2de
commit 4235556c16
2 changed files with 20 additions and 14 deletions

View file

@ -18,23 +18,22 @@ readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)
if(i == nil)
return nil;
}
p = nil;
if(read(fd, hdr, 3*12) != 3*12){
if(ai == nil)
freeimage(i);
werrstr("rdsubfonfile: header read error: %r");
return nil;
werrstr("readsubfont: header read error: %r");
goto Err;
}
n = atoi(hdr);
if(n <= 0 || n > 0x7fff){
werrstr("readsubfont: bad fontchar count %d", n);
goto Err;
}
p = malloc(6*(n+1));
if(p == nil)
goto Err;
if(read(fd, p, 6*(n+1)) != 6*(n+1)){
werrstr("rdsubfonfile: fontchar read error: %r");
Err:
if(ai == nil)
freeimage(i);
free(p);
return nil;
werrstr("readsubfont: fontchar read error: %r");
goto Err;
}
fc = malloc(sizeof(Fontchar)*(n+1));
if(fc == nil)
@ -51,6 +50,11 @@ readsubfonti(Display*d, char *name, int fd, Image *ai, int dolock)
}
free(p);
return f;
Err:
if(ai == nil)
freeimage(i);
free(p);
return nil;
}
Subfont*

View file

@ -25,6 +25,10 @@ openmemsubfont(char *name)
goto Err;
}
n = atoi(hdr);
if(n <= 0 || n > 0x7fff){
werrstr("openmemsubfont: bad fontchar count %d", n);
goto Err;
}
p = malloc(6*(n+1));
if(p == nil)
goto Err;
@ -46,9 +50,7 @@ openmemsubfont(char *name)
return sf;
Err:
close(fd);
if (i != nil)
freememimage(i);
if (p != nil)
free(p);
free(p);
freememimage(i);
return nil;
}