| Message ID | CAPinm07sZDi2R3YX7Js6x3o=fLPu5roGkSWtUpo1ua=oRqCgww@mail.gmail.com (mailing list archive) |
|---|---|
| State | Failed CI |
| Delegated to: | Avinal Kumar |
| Headers |
Return-Path: <libc-alpha-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 68CF54B920F9 for <patchwork@sourceware.org>; Sat, 26 Sep 2026 03:18:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68CF54B920F9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=CdLRG310 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx2-x0f.google.com (mail-yx2-x0f.google.com [IPv6:2607:f8b0:4864:41::f]) by sourceware.org (Postfix) with ESMTPS id 5F4234BB3BE8 for <libc-alpha@sourceware.org>; Sat, 26 Sep 2026 03:18:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F4234BB3BE8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5F4234BB3BE8 Authentication-Results: sourceware.org; arc=pass smtp.remote-ip=2607:f8b0:4864:41::f ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790392683; cv=pass; b=ld1OgIRonIknX2ZCeSGPqvDF/HT3HMzydbvPuABPdoTY1RlBHMyow9jGhSeJH42Tj07kimQyTIleCSgnTGuU+CfRsoIXG0eMbEq+GUxbA31UkQ86fFab686IIMlXQk97j08qFIql086CpmP5NT8PMq6XylONRKGeKLNp01RxpK0= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1790392683; c=relaxed/simple; bh=tahsxXAx2Ez//vxgSfdzJLGU4VkMaoWKQbCJemGWnTI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=pb/1q8vN5WITuAd0vXsuxcHmzorPmpT93WcIiHNDh1Uc4AMGOqh/giOgKOnJqYwnBLQPCTRSU4sViMDxadtEK8kFkfPEeoRa4GgY1N3Aqfy4Y6t+2Zb8JoUENHlLgVjTDA37BQsNvYTV/y9RsH4wQukSZKnlOJ0huIVQu/l9Q+M= ARC-Authentication-Results: i=2; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=CdLRG310 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F4234BB3BE8 Received: by mail-yx2-x0f.google.com with SMTP id 00721157ae682-895eaf31683so15973067b3.0 for <libc-alpha@sourceware.org>; Fri, 25 Sep 2026 20:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1790392683; cv=none; d=google.com; s=arc-20260327; b=NjWuPTMAEQuBHSGorji3UAgnysc7SwGmjCjKJWdRj0zChJpYhIifVwgHK2+mhMjv2K Z5xMnGFYgpBU9DRoa8TVsq0OicdXQUdpvh10GXmuoudvS9Izz1/KnrM/kih7DFknuDwg WXSivbdh555zcmGDjhMOziPVTZSAT9TeAf1e3e3aI6ymoGRCFuPHXSiw5wb7GXhb/Eoy MdvEd7zTRBiJ5z3rK70oN2k5fEv9/FH7GN0sEnSPqc+OZtgSbqUMACjPF9LF3acVCo0G MKTApT8McOdpdp13M3UymdDjOf3xvsGFWzkBCnFbDgtQY8CIs+vfXyktAzgYppwx6yMu O2fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=to:subject:message-id:date:from:mime-version:dkim-signature; bh=9QmQ1Lt6y9dXoQd6gJ2SDfy7/Nim/hkPFsf8mPtqojQ=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=I6Y8PvxBk80zg2UAKjsGNDnzJyN/o4NOsaNph+u+ysTAEiJxDH+ko+kj6VdKmPPoq5 msW8mwGUPhlUjvN0IaHSpWSvCRo+sjUwUdW2slgaHcmEnesAYMKJA4myYHSxHEyLsSOD v7zc1eQ1l/j79NcBAfvoypBw7fiaj/oV8dKzCUMLefd2OooWH8q+s5mvU1RKqltOsoLP zDkfBU8nU8JbvMM3ajMuaafqKkEV3XjS5wjHJBKfX257oM9mqgcdWai0ImrlHPjedNfY BebPl4Z4LFFGdV/zZkkrqNDQB7doQDKdyOSNZCnEG1x3iUZx6ZupZnMPdv7xKxU7jgey mNOQ==; darn=sourceware.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790392683; x=1790997483; darn=sourceware.org; h=content-type:to:subject:message-id:date:from:mime-version:from:to :cc:subject:date:message-id:reply-to:content-type; bh=9QmQ1Lt6y9dXoQd6gJ2SDfy7/Nim/hkPFsf8mPtqojQ=; b=CdLRG310iehL32M4XJ3n1hU+57x3ar1jK8zp76ln6CQE96jIA00NTAud6wNJMWgXVN 5jHbkTnfDR9A4RxpwRnnX7Z9e/oN3vHAbQnOevUNOo+L/V84zLqNxWPzJ12V2N35c1sV HW3JJPdIB2XugBFDoWrEcpioC7BBzsu8cwAPQKWpEVlyenxRBjZ0PVg70hxIFls1gpgn FL58DM6pAH1qLSEcW1NQz4Bm3yPs+Dghwgl6MHgFVfYHxWDnJ6ZN5SuV5lpbMSY4uTU1 2SU1dhwdX918i249HDnb6g/QaCrTNJJ/jcFZRE5Kv39v2cKY/4UBnmh5ZgKLvHARsExj t3eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790392683; x=1790997483; h=content-type:to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject: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MTP id 00721157ae682-8a876884faemr11038127b3.4.1790392682670; Fri, 25 Sep 2026 20:18:02 -0700 (PDT) Received: from 101988054943 named unknown by gmailapi.google.com with HTTPREST; Fri, 25 Sep 2026 23:18:02 -0400 Received: from 101988054943 named unknown by gmailapi.google.com with HTTPREST; Fri, 25 Sep 2026 23:18:02 -0400 MIME-Version: 1.0 From: Ekalabya Ghosh <ekalabya2010@gmail.com> Date: Fri, 25 Sep 2026 23:18:02 -0400 X-Gm-Features: AclHuK8Gvg94YUys2Ce1A_f-OM4x5nS7CqiBCclcwvkyjbl0MtQ6PsYBmYOdqEA Message-ID: <CAPinm07sZDi2R3YX7Js6x3o=fLPu5roGkSWtUpo1ua=oRqCgww@mail.gmail.com> Subject: [PATCH] nss_readline: move the NUL terminator along with leading-whitespace strip To: libc-alpha@sourceware.org Content-Type: multipart/alternative; boundary="000000000000dbef2f065c5a47d5" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
nss_readline: move the NUL terminator along with leading-whitespace strip
|
|
Checks
| Context | Check | Description |
|---|---|---|
| redhat-pt-bot/TryBot-apply_patch | fail | Patch failed to apply to master at the time it was sent |
| redhat-pt-bot/TryBot-32bit | fail | Patch series failed to apply |
Commit Message
Ekalabya Ghosh
Sept. 26, 2026, 3:18 a.m. UTC
From: Ekalabya Ghosh <ekalabya2010@gmail.com> Date: Sat, 26 Sep 2026 08:47:45 +0530 Subject: [PATCH] nss_readline: move the NUL terminator along with leading-whitespace strip __nss_readline() strips leading whitespace from a freshly-read database line by moving the remainder forward with "memmove (buf, p, strlen (p))". This moves the line's content but not its NUL terminator, which stays behind at its original, farther right position (the line's original, pre-strip length). The bytes between the newly shortened content and that stale terminator are the tail end of the original (pre-shift) line -- since the memmove only overwrites strlen (p) bytes starting at buf, positions at or beyond that offset keep whatever was already there, and the real terminator is further right than that. Reading the returned buffer back (e.g. via strlen) therefore includes those leftover bytes, appended after the line's own content. Concretely: for the two-space-indented line " hello\n" in an 8-plus-byte buffer, after stripping the leading whitespace the intended result is "hello\n" (6 bytes), but the buffer's terminator stays at its original offset (8), so bytes 6-7 -- which happen to still hold "o\n", the tail of the pre-strip line -- are included, and the caller sees "hello\no\n" (8 bytes) instead. This affects the last line of any nss_files-backed database (passwd, group, hosts, etc.) that has leading whitespace, appending extra, leftover bytes from the original line to the value the caller receives. It stays within the buffer (bounded by the earlier "buf[len - 1] == '\xff'" truncation check), so this is a data-correctness bug, not a memory-safety one. Move strlen (p) + 1 bytes instead, so the NUL terminator moves with the content it terminates, landing at the correct offset and leaving no stale bytes in between. Verified in an isolated harness extracting this exact code block: with a reused buffer whose tail (beyond the true line length) still held data from a previous iteration, the unfixed code returned 8 bytes including that leftover tail; the fixed code returns exactly the intended 6. I was not able to build the full glibc tree in the environment I found this in (glibc's build takes a base image / bootstrap toolchain this sandbox doesn't have), so this is verified against the extracted logic rather than the actual compiled __nss_readline, and I have not run the existing nss test suite -- please double check with that as part of review. Signed-off-by: Ekalabya Ghosh <ekalabya2010@gmail.com> --- nss/nss_readline.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) return 0;
Comments
On Sat, Sep 26, 2026 at 8:48 AM Ekalabya Ghosh <ekalabya2010@gmail.com> wrote: > > From: Ekalabya Ghosh <ekalabya2010@gmail.com> > Date: Sat, 26 Sep 2026 08:47:45 +0530 > Subject: [PATCH] nss_readline: move the NUL terminator along with leading-whitespace strip > > __nss_readline() strips leading whitespace from a freshly-read > database line by moving the remainder forward with > "memmove (buf, p, strlen (p))". This moves the line's content but > not its NUL terminator, which stays behind at its original, farther > right position (the line's original, pre-strip length). The bytes > between the newly shortened content and that stale terminator are the > tail end of the original (pre-shift) line -- since the memmove only > overwrites strlen (p) bytes starting at buf, positions at or beyond > that offset keep whatever was already there, and the real terminator > is further right than that. Reading the returned buffer back (e.g. > via strlen) therefore includes those leftover bytes, appended after > the line's own content. > > Concretely: for the two-space-indented line " hello\n" in an > 8-plus-byte buffer, after stripping the leading whitespace the > intended result is "hello\n" (6 bytes), but the buffer's terminator > stays at its original offset (8), so bytes 6-7 -- which happen to > still hold "o\n", the tail of the pre-strip line -- are included, > and the caller sees "hello\no\n" (8 bytes) instead. > > This affects the last line of any nss_files-backed database > (passwd, group, hosts, etc.) that has leading whitespace, appending > extra, leftover bytes from the original line to the value the caller > receives. It stays within the buffer (bounded by the earlier > "buf[len - 1] == '\xff'" truncation check), so this is a > data-correctness bug, not a memory-safety one. > Hi, I was able to reproduce the behavior. Although the practical impact is low to none. The further processing pipeline is tolerant and takes care of the trailing garbage. Can you please file a bug for the same https://sourceware.org/bugzilla/enter_bug.cgi?product=glibc and preferably attach a reproducer code? If you cannot do so, please let me know I will open a bug on your behalf. > I was not able to build the full glibc tree in the environment I > found this in (glibc's build takes a base image / bootstrap toolchain > this sandbox doesn't have), so this is verified against the extracted > logic rather than the actual compiled __nss_readline, and I have not > run the existing nss test suite -- please double check with that as > part of review. > The patch doesn't apply. There are random line breaks and missing space prefixes. I suspect the patch was copied using an HTML interface and that messed up the formatting. Regenerate the patch using git-format and use tools like git-send to submit. > Signed-off-by: Ekalabya Ghosh <ekalabya2010@gmail.com> > --- > nss/nss_readline.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/nss/nss_readline.c b/nss/nss_readline.c > index 08583e9d..fb0689cb 100644 > --- a/nss/nss_readline.c > +++ b/nss/nss_readline.c > @@ -71,7 +71,13 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset) > /* Skip empty lines and comments. */ > continue; > if (p != buf) > - memmove (buf, p, strlen (p)); > + /* Move the NUL terminator along with the line content. Moving > + only strlen (p) bytes leaves the previous (now stale) NUL > + terminator in its old, farther-right position, so the bytes > + between the newly shortened line and that old terminator > + -- leftover from the un-shifted tail of the original line -- > + are included in the result returned to the caller. */ The commit message already explains the rationale behind the fix. Reduce the comment to just explain the change; something like "Include the Null terminator" is enough. > + memmove (buf, p, strlen (p) + 1); > A test case would strengthen this patch. A line with leading whitespace in an NSS-format file fed through __nss_readline that asserts the returned string length matches the expected stripped content. Thank - Avinal
diff --git a/nss/nss_readline.c b/nss/nss_readline.c index 08583e9d..fb0689cb 100644 --- a/nss/nss_readline.c +++ b/nss/nss_readline.c @@ -71,7 +71,13 @@ __nss_readline (FILE *fp, char *buf, size_t len, off64_t *poffset) /* Skip empty lines and comments. */ continue; if (p != buf) - memmove (buf, p, strlen (p)); + /* Move the NUL terminator along with the line content. Moving + only strlen (p) bytes leaves the previous (now stale) NUL + terminator in its old, farther-right position, so the bytes + between the newly shortened line and that old terminator + -- leftover from the un-shifted tail of the original line -- + are included in the result returned to the caller. */ + memmove (buf, p, strlen (p) + 1); /* Return line to the caller. */