ref: 6d736d4205d6ae9dc9e2362994b96acee34baabc
parent: b4da1c54d9946de26a222fafffc8e583c1d707ad
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Apr 6 23:40:16 EDT 2025
gefs: allow large snapshot names in gefs when scanning the snapshot name table, a long snapshot would trigger an error copying the key-value pairs, and we could mutate the key we were looking up, leading to finding the wrong value; all other places where the user can control the input uses Kvmax for the size of the return buffer, so we should use that here. We should also separate the input and output variables in btlookup.
--- a/sys/src/cmd/gefs/fs.c
+++ b/sys/src/cmd/gefs/fs.c
@@ -615,18 +615,18 @@
{
static char *tagname[] = {"minute", "hour", "day"};
static int scale[] = {60, 3600, 24*3600};
- char *p, pfx[128], rbuf[128];
+ char *p, pfx[32], rbuf[Kvmax+1];
int i, n, div, cnt, op;
- Kvp kv;
+ Kvp kv, r;
pfx[0] = Kconf;
n = snprint(pfx+1, sizeof(pfx)-1, "retain");
kv.k = pfx;
kv.nk = n+1;
- if(btlookup(mnt->root, &kv, &kv, rbuf, sizeof(rbuf)-1)
- || btlookup(&fs->snap, &kv, &kv, rbuf, sizeof(rbuf)-1)){
- p[kv.nv] = 0;
- p = kv.v;
+ if(btlookup(mnt->root, &kv, &r, rbuf, sizeof(rbuf)-1)
+ || btlookup(&fs->snap, &kv, &r, rbuf, sizeof(rbuf)-1)){
+ p = r.v;
+ p[r.nv] = 0;
}else
p = "60@m 24@h @d";
while(*p){
--
⑨