From 1db5427df1a5dc0c7deb84def0395ce979b41455 Mon Sep 17 00:00:00 2001 From: JGZYES Date: Fri, 4 Sep 2026 20:26:57 +0800 Subject: [PATCH] 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)'). --- src/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 8ac8faf..9129fa3 100644 --- a/src/main.c +++ b/src/main.c @@ -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);