public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: Gao Xiang <gaoxiang@kylinos.cn>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v3] libio: Fix wide stream backup buffer leak on fclose [BZ #33999]
Date: Thu, 02 Apr 2026 14:47:41 +0200	[thread overview]
Message-ID: <mvmo6k1bkb6.fsf@suse.de> (raw)
In-Reply-To: <20260402062544.322321-1-gaoxiang@kylinos.cn> (Gao Xiang's message of "Thu, 2 Apr 2026 14:25:44 +0800")

On Apr 02 2026, Gao Xiang wrote:

> diff --git a/libio/tst-wbackup-leak.c b/libio/tst-wbackup-leak.c
> new file mode 100644
> index 0000000000..8a3e0fc1ed
> --- /dev/null
> +++ b/libio/tst-wbackup-leak.c
> @@ -0,0 +1,50 @@
> +/* Test _IO_wdefault_finish frees wide backup buffer [BZ #33999].  */
> +
> +#include <malloc.h>
> +#include <stdio.h>
> +#include <wchar.h>
> +#include <support/check.h>
> +
> +static void
> +one_round (void)
> +{
> +  wchar_t *buf = NULL;
> +  size_t size = 0;
> +
> +  FILE *fp = open_wmemstream (&buf, &size);
> +  TEST_VERIFY_EXIT (fp != NULL);
> +  fputwc (L'A', fp);
> +  fflush (fp);
> +  /* Push back without prior read. read_ptr == read_base, so
> +     _IO_wdefault_pbackfail skips the buggy narrow read_ptr access
> +     (BZ #33998) and goes straight to allocating a wide backup
> +     buffer at fp->_wide_data->_IO_save_base.
> +
> +     Note: this testcase relies on the fact that open_wmemstream
> +     does not set _IO_NO_READS on the stream. If that implementation
> +     is changed, this test would need a different stream type to verify
> +     the leak.  */
> +  ungetwc (L'Z', fp);

When switching from output to input mode a seek is required, so
prepending a rewind (fp) here would be needed.

Ok with that change.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

  reply	other threads:[~2026-04-02 12:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 13:35 [PATCH v2] " Gao Xiang
2026-04-01 13:56 ` Andreas Schwab
2026-04-02  6:25   ` [PATCH v3] " Gao Xiang
2026-04-02 12:47     ` Andreas Schwab [this message]
2026-04-03  1:57       ` [PATCH v4] " Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=mvmo6k1bkb6.fsf@suse.de \
    --to=schwab@suse.de \
    --cc=gaoxiang@kylinos.cn \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).