gefs: fix waserror() bugs

This commit is contained in:
cinap_lenrek 2025-01-05 00:12:16 +00:00
parent 2a622dfcec
commit 4de9d8a511
4 changed files with 336 additions and 207 deletions

View file

@ -233,6 +233,10 @@ checkdata(int, Tree *t)
while(1){ while(1){
if(!btnext(&s, &s.kv)) if(!btnext(&s, &s.kv))
break; break;
if(waserror()){
btexit(&s);
nexterror();
}
bp = unpackbp(s.kv.v, s.kv.nv); bp = unpackbp(s.kv.v, s.kv.nv);
if(isfree(bp.addr)){ if(isfree(bp.addr)){
fprint(2, "free block in use: %B\n", bp); fprint(2, "free block in use: %B\n", bp);
@ -240,6 +244,7 @@ checkdata(int, Tree *t)
} }
b = getblk(bp, GBraw); b = getblk(bp, GBraw);
dropblk(b); dropblk(b);
poperror();
} }
btexit(&s); btexit(&s);
return 0; return 0;
@ -288,16 +293,28 @@ checkfs(int fd)
if((t = opensnap(name, nil)) == nil){ if((t = opensnap(name, nil)) == nil){
fprint(2, "invalid snap label %s\n", name); fprint(2, "invalid snap label %s\n", name);
ok = 0; ok = 0;
poperror();
break; break;
} }
if(waserror()){
closesnap(t);
nexterror();
}
fprint(fd, "checking snap %s: %B\n", name, t->bp); fprint(fd, "checking snap %s: %B\n", name, t->bp);
b = getroot(t, &height); b = getroot(t, &height);
if(waserror()){
dropblk(b);
nexterror();
}
if(checktree(fd, b, height-1, nil, 0)) if(checktree(fd, b, height-1, nil, 0))
ok = 0; ok = 0;
if(checkdata(fd, t)) if(checkdata(fd, t))
ok = 0; ok = 0;
dropblk(b); dropblk(b);
poperror(); poperror();
closesnap(t);
poperror();
poperror();
} }
btexit(&s); btexit(&s);
adec(&fs->rdonly); adec(&fs->rdonly);

File diff suppressed because it is too large Load diff

View file

@ -154,8 +154,10 @@ dir2statbuf(Xdir *d, char *buf, int nbuf)
u = uid2user(nogroupid); u = uid2user(nogroupid);
if((m = uid2user(d->muid)) == nil) if((m = uid2user(d->muid)) == nil)
m = uid2user(noneid); m = uid2user(noneid);
if(u == nil || g == nil || m == nil) if(u == nil || g == nil || m == nil){
runlock(&fs->userlk);
error(Eperm); error(Eperm);
}
p = buf; p = buf;
nn = strlen(d->name); nn = strlen(d->name);

View file

@ -1238,16 +1238,12 @@ btupsert(Tree *t, Msg *msg, int nmsg)
for(i = 0; i < nmsg; i++) for(i = 0; i < nmsg; i++)
sz += msgsz(&msg[i]); sz += msgsz(&msg[i]);
npull = 0; npull = 0;
path = nil;
npath = 0;
Again: Again:
b = getroot(t, &height);
if(waserror()){ if(waserror()){
freepath(t, path, npath); dropblk(b);
nexterror(); nexterror();
} }
b = getroot(t, &height);
if(npull == 0 && b->type == Tpivot && !filledbuf(b, nmsg, sz)){ if(npull == 0 && b->type == Tpivot && !filledbuf(b, nmsg, sz)){
fastupsert(t, b, msg, nmsg); fastupsert(t, b, msg, nmsg);
poperror(); poperror();
@ -1258,9 +1254,14 @@ Again:
* split, so we allocate room for one extra * split, so we allocate room for one extra
* node in the path. * node in the path.
*/ */
npath = 0;
if((path = calloc((height + 2), sizeof(Path))) == nil) if((path = calloc((height + 2), sizeof(Path))) == nil)
error(Enomem); error(Enomem);
poperror();
if(waserror()){
freepath(t, path, height+2); /* npath not volatile */
nexterror();
}
npath = 0;
path[npath].b = nil; path[npath].b = nil;
path[npath].idx = -1; path[npath].idx = -1;
path[npath].midx = -1; path[npath].midx = -1;
@ -1278,6 +1279,7 @@ Again:
bp = unpackbp(sep.v, sep.nv); bp = unpackbp(sep.v, sep.nv);
b = getblk(bp, 0); b = getblk(bp, 0);
npath++; npath++;
assert(npath < height+2);
} }
path[npath].b = b; path[npath].b = b;
path[npath].idx = -1; path[npath].idx = -1;
@ -1347,6 +1349,13 @@ btlookup(Tree *t, Key *k, Kvp *r, char *buf, int nbuf)
dropblk(b); dropblk(b);
error(Enomem); error(Enomem);
} }
if(waserror()){
for(i = 0; i < h; i++)
dropblk(p[i]);
dropblk(b);
free(p);
nexterror();
}
ok = 0; ok = 0;
p[0] = holdblk(b); p[0] = holdblk(b);
for(i = 1; i < h; i++){ for(i = 1; i < h; i++){
@ -1377,10 +1386,10 @@ btlookup(Tree *t, Key *k, Kvp *r, char *buf, int nbuf)
} }
} }
for(i = 0; i < h; i++) for(i = 0; i < h; i++)
if(p[i] != nil) dropblk(p[i]);
dropblk(p[i]);
dropblk(b); dropblk(b);
free(p); free(p);
poperror();
return ok; return ok;
} }
@ -1417,6 +1426,10 @@ btenter(Tree *t, Scan *s)
dropblk(b); dropblk(b);
error(Enomem); error(Enomem);
} }
if(waserror()){
btexit(s);
nexterror();
}
p = s->path; p = s->path;
p[0].b = b; p[0].b = b;
for(i = 0; i < s->ht; i++){ for(i = 0; i < s->ht; i++){
@ -1443,6 +1456,7 @@ btenter(Tree *t, Scan *s)
p[i].vi++; p[i].vi++;
} }
s->first = 0; s->first = 0;
poperror();
} }
int int
@ -1459,7 +1473,7 @@ Again:
h = s->ht; h = s->ht;
start = h; start = h;
bufsrc = -1; bufsrc = -1;
if(s->donescan) if(p == nil || s->donescan)
return 0; return 0;
if(waserror()){ if(waserror()){
btexit(s); btexit(s);
@ -1545,4 +1559,6 @@ btexit(Scan *s)
for(i = 0; i < s->ht; i++) for(i = 0; i < s->ht; i++)
dropblk(s->path[i].b); dropblk(s->path[i].b);
free(s->path); free(s->path);
s->path = nil;
s->ht = 0;
} }