From 0630d978f1a1b5b96df817e077cd7ff804d9e95a Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Fri, 30 Oct 2026 01:26:02 +0000 Subject: [PATCH] upstream: clean up properly when stopping the progress meter, even if backgrounded and unable to output. Avoids reading free'd memory in a subsequent progress meter invocation if the right (wrong) sequence of backgrounding and forgroundings happened. Anthropic ANT-2026-4MDN97DH OpenBSD-Commit-ID: 40cc051b556697088851ec492bca2c00e1eac91e --- progressmeter.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/progressmeter.c b/progressmeter.c index 22f510a79..00340c6ec 100644 --- a/progressmeter.c +++ b/progressmeter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: progressmeter.c,v 1.57 2026/03/29 01:08:13 djm Exp $ */ +/* $OpenBSD: progressmeter.c,v 1.58 2026/10/30 01:26:02 djm Exp $ */ /* * Copyright (c) 2003 Nils Nordman. All rights reserved. * @@ -269,15 +269,21 @@ stop_progress_meter(void) { alarm(0); - if (!can_output()) - return; + if (can_output()) { + /* Ensure we complete the progress */ + if (cur_pos != end_pos) + refresh_progress_meter(1); + atomicio(vwrite, STDOUT_FILENO, "\n", 1); + } - /* Ensure we complete the progress */ - if (cur_pos != end_pos) - refresh_progress_meter(1); - - atomicio(vwrite, STDOUT_FILENO, "\n", 1); + /* + * Always forget the caller's file name and counter, even when we + * are not in the foreground and could not print; they don't outlive + * the transfer and must not be used by a later refresh. + */ file = NULL; + counter = NULL; + alarm_fired = 0; } static void