Collin Funk <collin.funk1@HIDDEN>
to control <at> debbugs.gnu.org.
Full text available.Collin Funk <collin.funk1@HIDDEN>
to control <at> debbugs.gnu.org.
Full text available.Received: (at 79808) by debbugs.gnu.org; 10 Nov 2025 16:49:12 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 10 11:49:12 2025 Received: from localhost ([127.0.0.1]:38637 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1vIV4q-000574-BE for submit <at> debbugs.gnu.org; Mon, 10 Nov 2025 11:49:12 -0500 Received: from mail.cs.ucla.edu ([131.179.128.66]:34304) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <eggert@HIDDEN>) id 1vIV4m-00056k-Lj for 79808 <at> debbugs.gnu.org; Mon, 10 Nov 2025 11:49:11 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 32A3C3C00516F; Mon, 10 Nov 2025 08:49:02 -0800 (PST) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id mmEpsMlXdoR1; Mon, 10 Nov 2025 08:49:02 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 09B3A3C09FCA5; Mon, 10 Nov 2025 08:49:02 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu 09B3A3C09FCA5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1762793342; bh=c7DJm/lna24JaXLYchYGjIWtLXEe1s2WAQHs1fYthL0=; h=Message-ID:Date:MIME-Version:To:From; b=MwyrQ5tPyn+WpShRl7db4LgNEbhVQqaL4axBynSY+ZrOcWtXtDlSJLVt0JiZO2RYz jOqm8v1lO9LxHrIeFuD7c6MH8rptMRwnivnHcJ2kZs18CJDNvlSUSIgxBy4S0lqbGO zdsMY3A7kV+fhYMeYT3rYQGnRouTnUbO1bNFIaFZIQGLXh10hoKYpBHzkx40NL2PYK SJbQx91GXT1zLSpdW9KUehD+GA1t8dnswNZe05A8MAEtFMTCU+OM6g6s1+3Q2x93C7 XOd3xaRBVpIM435J7CMGVH9nREJwpBI2PNckSDK6SbtDMCFOAoWYqrFn9z3hMpMOxK 7vkqBTj1qCMFg== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id te8qiwcHIcji; Mon, 10 Nov 2025 08:49:01 -0800 (PST) Received: from penguin.cs.ucla.edu (47-154-25-30.fdr01.snmn.ca.ip.frontiernet.net [47.154.25.30]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id DCD6C3C00516F; Mon, 10 Nov 2025 08:49:01 -0800 (PST) Message-ID: <0e7f172a-fe5a-4778-baa0-79c0673e2125@HIDDEN> Date: Mon, 10 Nov 2025 08:49:01 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bug#79808: Possible missing fclose() in tac_nonseekable (src/tac.c) To: Ray steven <checkscope.hyzc@HIDDEN>, =?UTF-8?Q?P=C3=A1draig_Brady?= <P@HIDDEN> References: <CAC2RF+Omu-g-Bv8dAhp+jEhJ73Um1zJQ_sBQ5ahkJ0tYtibk6g@HIDDEN> <549c264c-0b48-40ac-bd72-0aa0f4aa0e8d@HIDDEN> <CAC2RF+M2AdtZ0sqUEDPqtyqbsQtczj5Q0eWdOMzEkHJA_G3+Ow@HIDDEN> Content-Language: en-US From: Paul Eggert <eggert@HIDDEN> Organization: UCLA Computer Science Department In-Reply-To: <CAC2RF+M2AdtZ0sqUEDPqtyqbsQtczj5Q0eWdOMzEkHJA_G3+Ow@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 79808 Cc: 79808 <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) On 2025-11-10 04:53, Ray steven wrote: > it might still be a good > idea to > explicitly close the file once it=E2=80=99s no longer in use. Generally speaking we don't bother with explicit deallocation of=20 resources if not needed to avoid resource exhaustion. Such deallocation=20 complicates maintenance and slows down execution a bit, and in practice=20 these disadvantages outweigh the advantages of deallocation.
bug-coreutils@HIDDEN:bug#79808; Package coreutils.
Full text available.Received: (at 79808) by debbugs.gnu.org; 10 Nov 2025 12:54:03 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 10 07:54:03 2025 Received: from localhost ([127.0.0.1]:37657 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1vIRPG-0003bV-Pj for submit <at> debbugs.gnu.org; Mon, 10 Nov 2025 07:54:03 -0500 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]:61626) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <checkscope.hyzc@HIDDEN>) id 1vIRPE-0003b8-PK for 79808 <at> debbugs.gnu.org; Mon, 10 Nov 2025 07:54:01 -0500 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-44f7be0adcfso1412070b6e.2 for <79808 <at> debbugs.gnu.org>; Mon, 10 Nov 2025 04:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762779235; x=1763384035; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=okmv20sGzA1RgwZdUuS+fGEeuhq+uB6HENcxKfa/Uno=; b=ngr4i5k77jrfPBTb0l+/Y69rdYtBHLFEOXLOQIXt5OUx+8fWQlDcudkaV+AJcWRiRK u0yqFqqjeubMbSX3CjC9WcawuG+Dg++nbucBNe0+9OKJ+DFMBUTp6UZhsBxJpcVx7qAE baAIG8MOonpa7um8Pp2A9d7moxJmAlmLbW2mXGOx6VnyegWdf9h1MikwBANEQ5A4ab4k p35ORHsuoiKaFg6GczfQwcsBxHpJcfW85QsHfBXz8GNI5unpnm+bCvOST7ae0/2iglqc svLtkdP0yZctR2hQvFh1i2y4Uv+5hdXIX8GG/bHY+7bJAZD3jf9OyZPzBQDNqi215Mq0 KdSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762779235; x=1763384035; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=okmv20sGzA1RgwZdUuS+fGEeuhq+uB6HENcxKfa/Uno=; b=Y+LGaVrNxuewgo02wgCM/f6hd+0P6TyWoB0v2MJdqyWMKfzI1Kavu0G4xYsOHMmigR 9+p0SBgsGauDuWS3DkR4YyokVsPh9Dl3lBMOgBIdWN/i++lwtCaeRPX+wBWJBiOILEpa WCKC3U38RCVIq07mYaUpcrijdSbiTLod66iKmNLSt97ESS8XRfSAo+Dft7RFBOOQHLYS 6SUbnn4rtGMqdjAlqIWdxR+YY0OGP1oQZMf4FCaGiNcWv672yEUAlPcwFDoFRQWmU5et wSPnkp0M5TxQD7+VEcXwQo003XqBgzPCcs/nkzlRB6GqdsdAIIw+hSxuzCFWkCaQPmVc aHnw== X-Gm-Message-State: AOJu0YwWJ5QKoYN6XQmvxAbTvVypvlGMvcP2LAQEtUBzNAKVdkCVL5Gx G4YeFyC9OTkbXS7mr8vUQHXy09WmwYJIrrW+yo7+pAMS10MnHz3PWykx7cY9f1D9jZQn9QOURSj PWwPpGaREg0s3ItMjBU6eryeYh4ZBPWc= X-Gm-Gg: ASbGncu6AbN2jQFhzrIYLLejU5IXFjl3IksG9/TLGTKnJyuQOO0GEYdzJQVUU/6SoNk mGPFZB4z+h0ARWP0BINcQvSTON5PFZHultz0IzvA5SAC1a6b49C9Bw+obCKjeqUUw6jgg18mJ+4 aY8gdM++F+cKcYm3gTj9iyCs0iQx5cquLUNl5BxNlZpwG9S1LshdoyM15G0YhPhKej4mGvtScvL OHg1rQeYMA6SDqNNiZDmvu5aTsgK1IP55OMwUP6n9BNJwMnDnzkG5Vr044pHg== X-Google-Smtp-Source: AGHT+IFHShNEKzqLlPjKzmw3N9L8oNOFa8/oT7Nks/PSexvrXOF0TppqHagdwUL8raAjFfKy8OHngxBz/0vuxV7ZTHc= X-Received: by 2002:a05:6808:4fcf:b0:450:3c49:519 with SMTP id 5614622812f47-4503c490fd2mr2747526b6e.7.1762779234942; Mon, 10 Nov 2025 04:53:54 -0800 (PST) MIME-Version: 1.0 References: <CAC2RF+Omu-g-Bv8dAhp+jEhJ73Um1zJQ_sBQ5ahkJ0tYtibk6g@HIDDEN> <549c264c-0b48-40ac-bd72-0aa0f4aa0e8d@HIDDEN> In-Reply-To: <549c264c-0b48-40ac-bd72-0aa0f4aa0e8d@HIDDEN> From: Ray steven <checkscope.hyzc@HIDDEN> Date: Mon, 10 Nov 2025 20:53:43 +0800 X-Gm-Features: AWmQ_bk59wkkUwChIs-LCjNAfImMQfDcQoGzDhaiA9GanM8MDV9cTCC6s2A8Tec Message-ID: <CAC2RF+M2AdtZ0sqUEDPqtyqbsQtczj5Q0eWdOMzEkHJA_G3+Ow@HIDDEN> Subject: Re: bug#79808: Possible missing fclose() in tac_nonseekable (src/tac.c) To: =?UTF-8?Q?P=C3=A1draig_Brady?= <P@HIDDEN> Content-Type: multipart/alternative; boundary="0000000000001dc08f06433d060e" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 79808 Cc: 79808 <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) --0000000000001dc08f06433d060e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks, Padraig =E2=80=94 understood. While the current implementation works correctly, it might still be a good idea to explicitly close the file once it=E2=80=99s no longer in use. thanks, CheckScope On Mon, Nov 10, 2025 at 7:26=E2=80=AFPM P=C3=A1draig Brady <P@HIDDEN= m> wrote: > tag 79808 notabug > close 79808 > stop > > details below... > > On 10/11/2025 09:45, Ray steven wrote: > > Hello coreutils maintainers, > > > > While reviewing the source code of GNU coreutils (tac.c), I noticed a > small > > resource management > > issue in the function `tac_nonseekable()`: > > > > After calling `copy_to_temp(&tmp_stream, &tmp_file, input_fd, file)`, t= he > > function uses `tmp_stream` > > in `tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied)` but never > > calls `fclose(tmp_stream)` afterwards. > > As a result, the FILE stream and its underlying file descriptor remain > open > > until process termination. > > > > Although this does not cause user-visible problems for short-lived `tac= ` > > executions, adding an explicit > > `fclose(tmp_stream)` (and perhaps removing the temporary file) would > > improve resource hygiene and > > avoid potential descriptor exhaustion if the function were reused in a > > long-running context. > > > > Environment: > > - Observed in current `src/tac.c` (line ~423 in GNU coreutils latest) > > > > Suggested fix (simplified): > > ```c > > bool ok =3D tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied); > > fclose(tmp_stream); > > unlink(tmp_file); > > return ok; > > The temp-stream module manages a single global resource per process, > so this would be incorrect. > I verified that there is no leak with `tac - - - - -`. > > thanks, > Padraig > --0000000000001dc08f06433d060e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Thanks, Padraig =E2=80=94 understood. =C2=A0<br>While the = current implementation works correctly,=C2=A0it might still be a good idea = to=C2=A0<div>explicitly close the file once it=E2=80=99s no longer in use.<= /div><div><br></div><div>thanks,</div><div>CheckScope</div></div><br><div c= lass=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail_= attr">On Mon, Nov 10, 2025 at 7:26=E2=80=AFPM P=C3=A1draig Brady <<a hre= f=3D"mailto:P@HIDDEN">P@HIDDEN</a>> wrote:<br></div><blo= ckquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left= :1px solid rgb(204,204,204);padding-left:1ex">tag 79808 notabug<br> close 79808<br> stop<br> <br> details below...<br> <br> On 10/11/2025 09:45, Ray steven wrote:<br> > Hello coreutils maintainers,<br> > <br> > While reviewing the source code of GNU coreutils (tac.c), I noticed a = small<br> > resource management<br> > issue in the function `tac_nonseekable()`:<br> > <br> > After calling `copy_to_temp(&tmp_stream, &tmp_file, input_fd, = file)`, the<br> > function uses `tmp_stream`<br> > in `tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied)` but neve= r<br> > calls `fclose(tmp_stream)` afterwards.<br> > As a result, the FILE stream and its underlying file descriptor remain= open<br> > until process termination.<br> > <br> > Although this does not cause user-visible problems for short-lived `ta= c`<br> > executions, adding an explicit<br> > `fclose(tmp_stream)` (and perhaps removing the temporary file) would<b= r> > improve resource hygiene and<br> > avoid potential descriptor exhaustion if the function were reused in a= <br> > long-running context.<br> > <br> > Environment:<br> > - Observed in current `src/tac.c` (line ~423 in GNU coreutils latest)<= br> > <br> > Suggested fix (simplified):<br> > ```c<br> > bool ok =3D tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied);<= br> > fclose(tmp_stream);<br> > unlink(tmp_file);<br> > return ok;<br> <br> The temp-stream module manages a single global resource per process,<br> so this would be incorrect.<br> I verified that there is no leak with `tac - - - - -`.<br> <br> thanks,<br> Padraig<br> </blockquote></div> --0000000000001dc08f06433d060e--
bug-coreutils@HIDDEN:bug#79808; Package coreutils.
Full text available.Received: (at 79808) by debbugs.gnu.org; 10 Nov 2025 11:26:15 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 10 06:26:15 2025 Received: from localhost ([127.0.0.1]:37444 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1vIQ2I-0005q7-QN for submit <at> debbugs.gnu.org; Mon, 10 Nov 2025 06:26:15 -0500 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:47539) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from <pixelbeat@HIDDEN>) id 1vIQ2E-0005pz-Qb for 79808 <at> debbugs.gnu.org; Mon, 10 Nov 2025 06:26:13 -0500 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-471191ac79dso30296915e9.3 for <79808 <at> debbugs.gnu.org>; Mon, 10 Nov 2025 03:26:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762773964; x=1763378764; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=AX9cM6Ijpy/l0GPugbt4WKVmrB00lSJrEaJakYGbWhQ=; b=ZhuCsjl/GouBM/v/GZWvhNnamON9mbD8VAxPuOTVn1RLkBG5daAsrX7LsCxzeWbyhF K6TcoX8zLtQJZwVEf5BYAuWtQwwt0O/LwSnA41jBATQdGoawEKYjBdXXZhH8smwfHpDq suKvzWZUfoTNyWgByrHD4KI6+EyMZS0kr4C3JD9iKmEb1CuhVbMmrXyjiyQRY6LhTLb0 Jdf13MAn2V+Gc87Y/y9plfoUl9X1cTp2zgQbaR+nNQ5JC8XrsaZOwCPsrloAfZJKqM3M pTOfVaPHKkSEpLyVBHrLpfJliX7ATQCXAYE/oQu/+veISC2HT3qkCxZ3s6TXNp/hwTAz wlWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762773964; x=1763378764; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :sender:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AX9cM6Ijpy/l0GPugbt4WKVmrB00lSJrEaJakYGbWhQ=; b=gABm6c/iII92BWfkJ9+uIZrsQ1OPHTcz+2KXFLsf5jOMYBVfSd0DdQTLjgEJw67iq7 YweERM+jUmx3MwclHsgsUXk80C1eHh9piawSmrU+VLAegVgXTfAOsq1DqUy0m8z+h0xi mxtufikDnImVKsUylbU/ZtSX2vx5Ico/xGE7CmS+l5+UsESn2Zxs+uAL2yaADBukOyKt 0AXUypZ0/piOIS6bhk5TMZ6YDJd9qE2ZzjOmKVZMIGAdzoEP+r0uaZF4GmcCAhq2m1VS /VqAdrz+XXH8IgjAhlVwqk6l5kM9pWLBVzzNEAS2MF+id4kjCr5i4FcfYBow3T67+Ryn 591w== X-Forwarded-Encrypted: i=1; AJvYcCWBZRqfPRpkor36jQ8By/Jp6gjtsY6rBq5bq3s7AeuXIFRqmwkvzZMlwzFhVKy1Hm2+4SeHXQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0YzmU8tjSaA2PsXCg7GyfyHIIADzI1fKRJ5saf3C74BJJrfkkQ1y 141vz96uOWu9eTtboRF0NM1nQBke4CpPqk3ogM3f+vOJKxw58TudAPja X-Gm-Gg: ASbGncvb6XHUV5F6nuxCl76rpIOT/OD1DdEjrJW4eKe7gaNHwpoXooYG+yCYR2SrS5d KzDZ1JDZEjAZI4STNFnOOTIhUr9oUPF89DBTaqX4VySFW4KbJBt+/gMa6Qy1Ab8Mp9ffrnfmTPu T/pgAhsPm2ib8aePHZRe2il04Ml48Bd/7GVC8jlHm9eroIzBpT+462snX0EXGjdXY8NrGgHrkfR 6d9xkryA7cbmX6vw4gX/qaLm2F3x2tU7UKHna6COIsAfeav3CG6zoVMXemECFrf3bciFuc3Myvl uqj4MDMkhwS/BJabaH7XDZNgtUOxjfxGBVUsCfBEkmk+0BwSU4nHU/VEY0oWi1h/KsRHNl4b1X6 ZgKp/AOaeuAPmdxIoZHZsA9ZWtIVs+6FJWwwfiduA+4VzvlytpGNpKcpSqCmSLUzLEqx2/7ztvu 3+NS8DtEkcwA== X-Google-Smtp-Source: AGHT+IFlbQBVQoiZdUj4wjAT2zQkowPrCnv1ikh7GmHuS49rsPOV5XB+PcofRs7XnVpxtjS+5jIaiQ== X-Received: by 2002:a05:600c:6287:b0:475:df91:ddf0 with SMTP id 5b1f17b1804b1-4777327cdaamr75443985e9.33.1762773964187; Mon, 10 Nov 2025 03:26:04 -0800 (PST) Received: from [192.168.1.31] ([86.44.211.146]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-4776bd08834sm201454785e9.15.2025.11.10.03.26.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Nov 2025 03:26:03 -0800 (PST) Message-ID: <549c264c-0b48-40ac-bd72-0aa0f4aa0e8d@HIDDEN> Date: Mon, 10 Nov 2025 11:25:56 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: bug#79808: Possible missing fclose() in tac_nonseekable (src/tac.c) To: Ray steven <checkscope.hyzc@HIDDEN>, 79808 <at> debbugs.gnu.org References: <CAC2RF+Omu-g-Bv8dAhp+jEhJ73Um1zJQ_sBQ5ahkJ0tYtibk6g@HIDDEN> Content-Language: en-US From: =?UTF-8?Q?P=C3=A1draig_Brady?= <P@HIDDEN> In-Reply-To: <CAC2RF+Omu-g-Bv8dAhp+jEhJ73Um1zJQ_sBQ5ahkJ0tYtibk6g@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 79808 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) tag 79808 notabug close 79808 stop details below... On 10/11/2025 09:45, Ray steven wrote: > Hello coreutils maintainers, > > While reviewing the source code of GNU coreutils (tac.c), I noticed a small > resource management > issue in the function `tac_nonseekable()`: > > After calling `copy_to_temp(&tmp_stream, &tmp_file, input_fd, file)`, the > function uses `tmp_stream` > in `tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied)` but never > calls `fclose(tmp_stream)` afterwards. > As a result, the FILE stream and its underlying file descriptor remain open > until process termination. > > Although this does not cause user-visible problems for short-lived `tac` > executions, adding an explicit > `fclose(tmp_stream)` (and perhaps removing the temporary file) would > improve resource hygiene and > avoid potential descriptor exhaustion if the function were reused in a > long-running context. > > Environment: > - Observed in current `src/tac.c` (line ~423 in GNU coreutils latest) > > Suggested fix (simplified): > ```c > bool ok = tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied); > fclose(tmp_stream); > unlink(tmp_file); > return ok; The temp-stream module manages a single global resource per process, so this would be incorrect. I verified that there is no leak with `tac - - - - -`. thanks, Padraig
bug-coreutils@HIDDEN:bug#79808; Package coreutils.
Full text available.Received: (at submit) by debbugs.gnu.org; 10 Nov 2025 09:45:40 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 10 04:45:40 2025 Received: from localhost ([127.0.0.1]:36949 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1vIOSy-0000SQ-1w for submit <at> debbugs.gnu.org; Mon, 10 Nov 2025 04:45:40 -0500 Received: from lists.gnu.org ([2001:470:142::17]:41142) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <checkscope.hyzc@HIDDEN>) id 1vIOSv-0000Rt-KT for submit <at> debbugs.gnu.org; Mon, 10 Nov 2025 04:45:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <checkscope.hyzc@HIDDEN>) id 1vIOSm-00089P-Rn for bug-coreutils@HIDDEN; Mon, 10 Nov 2025 04:45:29 -0500 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <checkscope.hyzc@HIDDEN>) id 1vIOSk-0004Ly-3S for bug-coreutils@HIDDEN; Mon, 10 Nov 2025 04:45:28 -0500 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-656de56ce7aso184563eaf.3 for <bug-coreutils@HIDDEN>; Mon, 10 Nov 2025 01:45:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762767924; x=1763372724; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=9ngLhwmfJTYQACvfsnqHApYq8zuucBrBwdS41kNII60=; b=INvYkG0Wvo63v+eKIdphZ3aOqNkHORiu2UB003fkn4S2ZLMzNIcP0YDaLsnMWxvJ9/ E1L1kuCGhMK0/86yX5VYx3nQS9zBRKH9Ai4ImEYBbZr3a+rfrS1kU5hylyi3KtjoHtn4 ecN0DohyZeZ/6ZrvWIqhBrrjlk3HE36KlonF1YjweJ2ABVtR+oFIu89S47j9ET6A6esP 5MT6SF4NfSvdA5v1rz0acOsIGtShfF6LVkNqftcf+rUxnWIXQWtef/igfipx50PPmff/ GURVeeyIfAdBRxMFZOb5YZyhkGSdO9dHRxmt+oD/iCzyKTtXuLH1v4LycxcfHgOfF/E3 K+bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762767924; x=1763372724; h=to:subject:message-id:date:from:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9ngLhwmfJTYQACvfsnqHApYq8zuucBrBwdS41kNII60=; b=WrNk5bWoBq7gOFlaXaoMmrHQOsacKD+iwGvXvwBssAn6fCVgsKd3T3YDxHnByEztvU QF93IiK/xMkBjCJdLZJSgy/fWW0u6npePfMFkdsNOVaz0XGZMpJr9jJC07KYCzMbrL7P vK0/NM20WgljLIuavP3wtvhpXPp2tNMXoIPPyLWmc3r7QufN3DZ8RlPfB+zrZKIQzRLo 1LVKF6CewBLSyxYpqiiN30TsD5kZ4pGcrR83dXzqAoy5vtT5++cpHQh57QI6jbqohUph m27me8hFBeZ/n1iGeOwwXn7rkJiIGBWtEf+ZFCxz2KcP/Bx82f6NyOHueYWC6tS0Iro3 kTRQ== X-Gm-Message-State: AOJu0YwEPAJXZAk1dap5080PgGyPtHSkVQz68UjdrVzQqUDK0w2yjnTS HECYRzBwL43N2Z8xXutrgrhaPSeCzhhDDCOOQhrFd+5sZnfmhWYtk3AVG7Sz21FYi6xJYhlj+cw eg7qtV5mvGPWPGBdwYcF/IV4uryLl8aFD/bkF X-Gm-Gg: ASbGnctYx/RZuKFOc7zTUBvzWE7FuRgG2+eF1C9lvGt3flZNu7KzrNVW7Bv4ZtzT125 jCbPSUXgrpEgSpBWveK1PezNUlWnOHgeKNyp7bISOLTWlxQURbbpRdcYorS9ZS0X1XXL6v38Vej BUld50Ffs+FyhrjejRAiOOWyL7vycfJMZdl2orta+1BFLHoD9T/tY2M0DAj3UkgMMYOAPUwpa4g SW/VDXN+0m4FyNg9ITE+p9hedZXB7jTvKnu24lZkhmXJyxGZKYnOmEyclho/Q== X-Google-Smtp-Source: AGHT+IFE5fT+Z48+jGgxtrdaohZrMt8y0+4pCEJD9ldf9raZvXn18zWjRm00suKwaROP/cgzd8VF6lccAxXUHqm1hxU= X-Received: by 2002:a05:6808:2f18:b0:44d:b760:f1bf with SMTP id 5614622812f47-4502a241773mr4633671b6e.30.1762767924182; Mon, 10 Nov 2025 01:45:24 -0800 (PST) MIME-Version: 1.0 From: Ray steven <checkscope.hyzc@HIDDEN> Date: Mon, 10 Nov 2025 17:45:11 +0800 X-Gm-Features: AWmQ_bmOcrQGNgbNssjx1fkDskexo4__PvSHPNP6GCpz26SjFotqijPWx3S2F1w Message-ID: <CAC2RF+Omu-g-Bv8dAhp+jEhJ73Um1zJQ_sBQ5ahkJ0tYtibk6g@HIDDEN> Subject: Possible missing fclose() in tac_nonseekable (src/tac.c) To: bug-coreutils@HIDDEN Content-Type: multipart/alternative; boundary="000000000000f142f006433a63b9" Received-SPF: pass client-ip=2607:f8b0:4864:20::c34; envelope-from=checkscope.hyzc@HIDDEN; helo=mail-oo1-xc34.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.0 (/) --000000000000f142f006433a63b9 Content-Type: text/plain; charset="UTF-8" Hello coreutils maintainers, While reviewing the source code of GNU coreutils (tac.c), I noticed a small resource management issue in the function `tac_nonseekable()`: After calling `copy_to_temp(&tmp_stream, &tmp_file, input_fd, file)`, the function uses `tmp_stream` in `tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied)` but never calls `fclose(tmp_stream)` afterwards. As a result, the FILE stream and its underlying file descriptor remain open until process termination. Although this does not cause user-visible problems for short-lived `tac` executions, adding an explicit `fclose(tmp_stream)` (and perhaps removing the temporary file) would improve resource hygiene and avoid potential descriptor exhaustion if the function were reused in a long-running context. Environment: - Observed in current `src/tac.c` (line ~423 in GNU coreutils latest) Suggested fix (simplified): ```c bool ok = tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied); fclose(tmp_stream); unlink(tmp_file); return ok; Best regards, CheckScope --000000000000f142f006433a63b9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Hello coreutils maintainers,<br><br>While reviewing the so= urce code of GNU coreutils (tac.c), I noticed a small resource management= =C2=A0<div>issue in the function `tac_nonseekable()`:<br><br>After calling = `copy_to_temp(&tmp_stream, &tmp_file, input_fd, file)`, the functio= n uses `tmp_stream`=C2=A0</div><div>in `tac_seekable(fileno(tmp_stream), tm= p_file, bytes_copied)` but never calls `fclose(tmp_stream)` afterwards. =C2= =A0<br>As a result, the FILE stream and its underlying file descriptor rema= in open until process termination.<br><br>Although this does not cause user= -visible problems for short-lived `tac` executions, adding an explicit=C2= =A0</div><div>`fclose(tmp_stream)` (and perhaps removing the temporary file= ) would improve resource hygiene and=C2=A0</div><div>avoid potential descri= ptor exhaustion if the function were reused in a long-running context.<br><= br>Environment: =C2=A0<br>- Observed in current `src/tac.c` (line ~423 in G= NU coreutils=C2=A0latest)<br><br>Suggested fix (simplified):<br>```c<br>boo= l ok =3D tac_seekable(fileno(tmp_stream), tmp_file, bytes_copied);<br>fclos= e(tmp_stream);<br>unlink(tmp_file);<br>return ok;<br></div><div><br></div><= div><br></div><div>=C2=A0 Best regards,<br></div><div>=C2=A0 CheckScope</di= v></div> --000000000000f142f006433a63b9--
Ray steven <checkscope.hyzc@HIDDEN>:bug-coreutils@HIDDEN.
Full text available.bug-coreutils@HIDDEN:bug#79808; Package coreutils.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.