fix(upgrade): copy best version to a stable buffer before json_free

The latest-version pointer from json_str() dangles after json_free(root),
so pmm upgrade printed garbage for the target version. Copy it into a local
buf before freeing the JSON tree (now shows e.g. 'pureftpd 1.0.51 is up to
date (latest 1.0.51)').
这个提交包含在:
JGZYES
2026-09-04 20:26:57 +08:00
父节点 51a88a4678
当前提交 1db5427df1
+6 -2
查看文件
@@ -366,12 +366,16 @@ static int cmd_upgrade(int argc, char **argv) {
} else {
best = json_str(root, "version");
}
/* Copy best into a stable buffer BEFORE freeing the JSON tree: best
* currently points into json_str()'s internal storage. */
char bestbuf[128];
if (best) snprintf(bestbuf, sizeof(bestbuf), "%s", best);
json_free(root);
if (!best) continue;
if (cmp_version(best, curver) <= 0) { pmm_info("%s %s is up to date (latest %s)\n", pkg, curver, best); continue; }
if (cmp_version(bestbuf, curver) <= 0) { pmm_info("%s %s is up to date (latest %s)\n", pkg, curver, bestbuf); continue; }
pmm_info("%s: %s -> %s\n", pkg, curver, best);
pmm_info("%s: %s -> %s\n", pkg, curver, bestbuf);
if (!yes) {
printf(" upgrade? [y/N] ");
fflush(stdout);