netif: fix potential memory leak in netifwstat()

convM2D() might fault and raise error, leaking
sizeof(Dir)+n allocation.
This commit is contained in:
cinap_lenrek 2025-01-07 06:49:40 +00:00
parent 00c25292d7
commit 705a2c3c28

View file

@ -418,11 +418,13 @@ netifwstat(Netif *nif, Chan *c, uchar *db, int n)
error(Eperm); error(Eperm);
dir = smalloc(sizeof(Dir)+n); dir = smalloc(sizeof(Dir)+n);
m = convM2D(db, n, &dir[0], (char*)&dir[1]); if(waserror()){
if(m == 0){
free(dir); free(dir);
error(Eshortstat); nexterror();
} }
m = convM2D(db, n, &dir[0], (char*)&dir[1]);
if(m == 0)
error(Eshortstat);
if(!emptystr(dir[0].uid)){ if(!emptystr(dir[0].uid)){
strncpy(f->owner, dir[0].uid, KNAMELEN-1); strncpy(f->owner, dir[0].uid, KNAMELEN-1);
f->owner[KNAMELEN-1] = 0; f->owner[KNAMELEN-1] = 0;
@ -430,6 +432,7 @@ netifwstat(Netif *nif, Chan *c, uchar *db, int n)
if(dir[0].mode != ~0UL) if(dir[0].mode != ~0UL)
f->mode = dir[0].mode; f->mode = dir[0].mode;
free(dir); free(dir);
poperror();
return m; return m;
} }