GNU bug report logs - #79780
Resource leak in change_file_context() in src/chcon.c (coreutils Latest)

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Reported by: Ray steven <checkscope.hyzc@HIDDEN>; Keywords: notabug; Done: Pádraig Brady <P@HIDDEN>; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at 79780 <at> debbugs.gnu.org:


Received: (at 79780) by debbugs.gnu.org; 8 Nov 2025 10:43:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 08 05:43:29 2025
Received: from localhost ([127.0.0.1]:50930 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vHgPp-0007hX-9J
	for submit <at> debbugs.gnu.org; Sat, 08 Nov 2025 05:43:29 -0500
Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:42330)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <pixelbeat@HIDDEN>)
 id 1vHgPm-0007hN-FC
 for 79780 <at> debbugs.gnu.org; Sat, 08 Nov 2025 05:43:27 -0500
Received: by mail-wm1-x330.google.com with SMTP id
 5b1f17b1804b1-477563e28a3so10725425e9.1
 for <79780 <at> debbugs.gnu.org>; Sat, 08 Nov 2025 02:43:26 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1762598600; x=1763203400; darn=debbugs.gnu.org;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc:to:subject:user-agent:mime-version:date:message-id
 :sender:from:to:cc:subject:date:message-id:reply-to;
 bh=u91oHMTwEeE8wb9iOpIB2EzdtFEz34xLTMRzM6fKPIg=;
 b=aPEU5gG9V2qMFRrNxWY1eZeDzf/6tbdYvdA6UzO9rB4hlwBJWFPslzmLQsXhZsgHcj
 1rplFvl/PbbJvhDC2EB+MySSw1KqFs8cT49Tp4znSxLaBzoxiZiM/ywauDA7ub5XtxKC
 sPPeyrprbOBTGpfKSqmrCYeIQNpp6b1Z9qNB6PQCnW0yMYnDc3skiBL+1LbmgJVqfnEe
 sBQtUmd2cd+/T1him7CK32R+DQfBClIKLlWMFN+Z1z5K2qzxQVpZSkpUBUb73E5MYuPB
 KFs4MNnvGRCxDc6dHK4Pj3TEeY/wwm28SHpdfEdeW/uTDWOBHT6yW934yHlSlhICD5Na
 fzZw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1762598600; x=1763203400;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc: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=u91oHMTwEeE8wb9iOpIB2EzdtFEz34xLTMRzM6fKPIg=;
 b=C+I132oDXubgiLJRmHFcwXFVzZbjYlGdZqb/A8tH8qJ5PfQMxG82733waQWglW0wQq
 nvzc0rBZD493lql9xXZ9VxgLjA8w4+obLkE1DKvG2bfo3vzM+cb/SfnqMMGZo6KluUcl
 V7nV6hDV9+peYVIy4OrpON2RZniAwOBvem+NTDWwOgLMdlsLOPYPQy9qosLS+Q6xoY5S
 3Hw3dlLPBdGnzQ7FCyef8QRGJJGTRkZ6yvsZ7giAjvZG+ojIe8uVCWgVd7crSh3bD09V
 /5wkMKkaR2qKgfuuHLwXtfJIdWJ4kETypEFP+0vr6Jwv964QH6BvpnRG1hDATrN5fXNi
 NwHA==
X-Gm-Message-State: AOJu0YyXfSq9rvOX0mT1FyniUL9zIJ2pKX5ytlMGLgchKo6h0aQfKj0E
 OK9dRrbR7Yu17Tk7SG83/FrWc/lniV++giyejTH+uG9M20rUWVcSZaTi
X-Gm-Gg: ASbGncs2jU9RKYQQGk5oQ0GheIGT4LE1yRz9dmJid/mkwMIFJ90A7Td03qQ7/N6q36C
 ULTcELcCqcyCtWs4k9ifEMwl/UY9ixnk7lfhCJZGdbFDCLA9Yu1rUlMgEOpLIgDThe7ZR4d4Iqm
 w3prvvK11vCjpp4Rjwik9JqEYWASVO9Ib6iAgsd0rEhUWe5sz2sZoR2hZuMJ4ee2QQn/oSI+433
 WSiLJ4AoSZPrZud1dzhO+y9y+Jp7cMV3PLoSD1OxKcaghDzVg1+pwq6D2g74cruJWO9bL+VSvCl
 rQMnJiU7unciNeW56P4eb/GtJYGd4ecWHiFcb4tfpoq8YBFrykoc2ogbTYV7sU9nd1nxvrpQE3z
 U8gDf+UuWnf1q0A/UOas4Kj0VEpmR73zRpwpjwsiDIFWxQP5S3gbHhRiP6tueAPj1Sl4/0abFfS
 6uXHkWP7tlpA==
X-Google-Smtp-Source: AGHT+IFCdOhmgTCgMh/JYmPIDRInsTyNcqiMLT4BDkT4GxqOVQGIY8Tyqck3vgp+qrw9IdFOCh1AkA==
X-Received: by 2002:a05:600c:35c6:b0:475:f16f:6e10 with SMTP id
 5b1f17b1804b1-47772e04078mr20416535e9.18.1762598600028; 
 Sat, 08 Nov 2025 02:43:20 -0800 (PST)
Received: from [192.168.1.31] ([86.44.211.146])
 by smtp.googlemail.com with ESMTPSA id
 5b1f17b1804b1-47776b01ff7sm7654845e9.1.2025.11.08.02.43.19
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Sat, 08 Nov 2025 02:43:19 -0800 (PST)
Message-ID: <b9f578fd-909f-42a2-8ea8-51acb763734b@HIDDEN>
Date: Sat, 8 Nov 2025 10:43:12 +0000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird Beta
Subject: Re: bug#79780: Resource leak in change_file_context() in src/chcon.c
 (coreutils Latest)
To: Ray steven <checkscope.hyzc@HIDDEN>
References: <CAC2RF+MoNJYeON=uxcL9qH9jxZyVTAJhmnzQettwJqSyAmGGog@HIDDEN>
 <dfb33d7f-a6c8-4a26-8d4d-c461b8a2ab31@HIDDEN>
 <CAC2RF+Ptffwf1KTWSMejoR=cKPQXZcAe1nfdgc+hvHfidZb5+A@HIDDEN>
Content-Language: en-US
From: =?UTF-8?Q?P=C3=A1draig_Brady?= <P@HIDDEN>
In-Reply-To: <CAC2RF+Ptffwf1KTWSMejoR=cKPQXZcAe1nfdgc+hvHfidZb5+A@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 79780
Cc: 79780 <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 08/11/2025 09:01, Ray steven wrote:
>   The compute_context_from_mask() function only frees the copied context created by
>   context_new (new_context), but does not free the original context passed in.
>   This may cause a memory leak.

Oh indeed.
I've pushed a fix for that now.

thanks!
Padraig




Information forwarded to bug-coreutils@HIDDEN:
bug#79780; Package coreutils. Full text available.
bug closed, send any further explanations to 79780 <at> debbugs.gnu.org and Ray steven <checkscope.hyzc@HIDDEN> Request was from Pádraig Brady <P@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) notabug. Request was from Pádraig Brady <P@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 79780 <at> debbugs.gnu.org:


Received: (at 79780) by debbugs.gnu.org; 7 Nov 2025 15:55:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 07 10:55:41 2025
Received: from localhost ([127.0.0.1]:46539 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vHOoO-0005Ra-Sn
	for submit <at> debbugs.gnu.org; Fri, 07 Nov 2025 10:55:41 -0500
Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:46236)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.84_2) (envelope-from <pixelbeat@HIDDEN>)
 id 1vHOoM-0005RN-Fu
 for 79780 <at> debbugs.gnu.org; Fri, 07 Nov 2025 10:55:39 -0500
Received: by mail-wr1-x429.google.com with SMTP id
 ffacd0b85a97d-3ee64bc6b90so642974f8f.0
 for <79780 <at> debbugs.gnu.org>; Fri, 07 Nov 2025 07:55:38 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1762530932; x=1763135732; 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=Az4IqiS7bN0Un+byCaHYvBEUv3BPJ5UeVKlMjf991vA=;
 b=G63KIphPWYWtlEf5avthaOHBteEBHPz5KYcxns7o37O0oKHNz4Sne2eRxaUV73mWQj
 R+UuQeG3+5GMGkjFjNtqxjkmQ5V4JYtohzkxOJjSvGsSXv4yzAEALJ8RMUIjbCBvrNxC
 3UJ993z7eQcH/XzHybeqLPc+jdxIV2mbnXIznNgV5YjrNsNxakMZoku3svi4B+QbYHVW
 trGWZFYawN46L1tU73rdhGR70shTKJtI176JY82ei9G17rIdk+s0jkTe3odxZvpSMzob
 4CXLUnROS3AVhYkmR21+aTGmlXCSyTDPS4nq3PeBMayYSNuGYz2fhl2rPv3oJS+UdFVW
 Uidg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1762530932; x=1763135732;
 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=Az4IqiS7bN0Un+byCaHYvBEUv3BPJ5UeVKlMjf991vA=;
 b=Q1/eGF0Sp3Hnr0mGKQxwoJFQX6Hj2LpsQGQFH+PnZYi6xd9fhduU6YtEFVTyHrC1pe
 FgC4UPEsklUa1+SBnYxTy0cPYWI5luU8XbqTrmdYBBfFHnooNLOOEMsjoN3o6GquEon1
 qxRJ8sfJAvcSkMusRQ3YBufkRgz7H0Yuif8VoKglrWIDa1KLiOQDREufs43T5u/iyc4m
 YW43ifdUK8i40Y9Kbdfo2fQU0qyJm2g31DKr/MoP8kBEPNXGKpwtbiWyXkLHdlPOvqZb
 xo3L1hMoGhD6dx2feSwocFl1+at2QDZlgjn6nz2QPYBIfhzgvkVXPrpvOD01IFNwc8BC
 qklg==
X-Forwarded-Encrypted: i=1;
 AJvYcCXLlGacm2Pn/+zG9g97nucKw6AHlY3p0pYMZBadI0UC2qqomzv1KFcQ2G6UifqlTCIekt+SVg==@debbugs.gnu.org
X-Gm-Message-State: AOJu0Yw1lqglmeHjbraEmMU/tyouRVMlr9DfYWJegTOg4o0tgCa6qAqA
 a1rxWvU/i8yuoTkV7MsakmVgwpX/d4dmYnRDtdhcUxwYgasKqBx7cPP1
X-Gm-Gg: ASbGncu86NXWskaq4Dz1bKJslnblOK87EJylkWfASrEdaN7EvNlc+FwoyoyeinyYrq8
 yxSQcnCiBM+dt/Kc52B7u0jZC79inHc4SUJQ8gvvXqAGCU92lfnISWKmmq7mw+bw/QNEXetKdDc
 SX4V3+qqUpwzJc8R/R1vcZKwX7Y9OLkpxt7/F4Iqt0wBh48ZRbXBNvBluOiEnkplW5+1FVyMZeF
 bySRvZl/LEDfAe16upY1XLv2Vd8lVKHyvQ1+tqN32XsDGWMisMu3mXRM3tsOv1Gs10/wDD/UNyq
 w5TEIGwOXewvNoiwei2G1zMdrzEqTzUkuplvpido88EDLKGRcWImBSr2zQB3wvy2nG3Hbl6UHsl
 JpGoNwqr4u1ip7/1cQsCSl6FRHlfvCA5qLARl/0sapoS43ZTFsZ6AEgQqWM/IynVdQQkZDUayE/
 g=
X-Google-Smtp-Source: AGHT+IEb6djtjB0G2dzhh1Ux4VDYeyKAPKIi3HKfj9n8v7fo9GrFhyPQyQCCKuh9fp4qzpRONQOUvw==
X-Received: by 2002:adf:9c84:0:b0:429:cacf:107e with SMTP id
 ffacd0b85a97d-42ae5881270mr2486696f8f.19.1762530932035; 
 Fri, 07 Nov 2025 07:55:32 -0800 (PST)
Received: from [192.168.1.31] ([86.44.211.146])
 by smtp.googlemail.com with ESMTPSA id
 ffacd0b85a97d-42abe62bf4bsm5866274f8f.8.2025.11.07.07.55.31
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Fri, 07 Nov 2025 07:55:31 -0800 (PST)
Message-ID: <dfb33d7f-a6c8-4a26-8d4d-c461b8a2ab31@HIDDEN>
Date: Fri, 7 Nov 2025 15:55:23 +0000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird Beta
Subject: Re: bug#79780: Resource leak in change_file_context() in src/chcon.c
 (coreutils Latest)
To: Ray steven <checkscope.hyzc@HIDDEN>, 79780 <at> debbugs.gnu.org
References: <CAC2RF+MoNJYeON=uxcL9qH9jxZyVTAJhmnzQettwJqSyAmGGog@HIDDEN>
Content-Language: en-US
From: =?UTF-8?Q?P=C3=A1draig_Brady?= <P@HIDDEN>
In-Reply-To: <CAC2RF+MoNJYeON=uxcL9qH9jxZyVTAJhmnzQettwJqSyAmGGog@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 79780
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 79780 notabug
close 79780
stop

details below...

On 07/11/2025 10:28, Ray steven wrote:
> Subject: [BUG] Resource leak in change_file_context() in src/chcon.c
> (coreutils 9.x)
> 
> Hello Coreutils maintainers,
> 
> I discovered a potential resource leak at lines 170-171 in the function
> `change_file_context()` in `src/chcon.c`.
> 
> Bug Summary
> ------------
> A resource leak occurs when `specified_context` is NULL and
> `compute_context_from_mask()` fails. In this error path, the previously
> obtained `file_context` (via `getfileconat()` or `lgetfileconat()`) is not
> released, resulting in a memory leak. According to the official
> documentation, the caller must use `freecon()` to manually release the
> memory returned by `getfileconat()` or `lgetfileconat()`.
> 
> Suggested Fix
> -------------
> Call `freecon(file_context);` before returning when
> `compute_context_from_mask()` fails. For example:
> 
>      if (compute_context_from_mask(file_context, &context) != 0)
>      {
>          freecon(file_context);
>          return 1;
>      }

compute_context_from_mask() will do the free upon failure,
so there is no need for the explicit freecon() in this case.

thanks,
Padraig




Information forwarded to bug-coreutils@HIDDEN:
bug#79780; Package coreutils. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 7 Nov 2025 12:35:32 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Nov 07 07:35:32 2025
Received: from localhost ([127.0.0.1]:45656 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vHLgh-0005bF-Nr
	for submit <at> debbugs.gnu.org; Fri, 07 Nov 2025 07:35:32 -0500
Received: from lists.gnu.org ([2001:470:142::17]:35282)
 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 1vHJi8-0005u7-43
 for submit <at> debbugs.gnu.org; Fri, 07 Nov 2025 05:28:52 -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 1vHJi0-0005nA-0U
 for bug-coreutils@HIDDEN; Fri, 07 Nov 2025 05:28:44 -0500
Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e])
 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 1vHJhy-0004hh-BU
 for bug-coreutils@HIDDEN; Fri, 07 Nov 2025 05:28:43 -0500
Received: by mail-oa1-x2e.google.com with SMTP id
 586e51a60fabf-3e2f4c5b26dso165839fac.0
 for <bug-coreutils@HIDDEN>; Fri, 07 Nov 2025 02:28:41 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1762511320; x=1763116120; darn=gnu.org;
 h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
 :date:message-id:reply-to;
 bh=YwJDYAiRAn67jAdYYlitqsFvX+Ia8OhH74XdKSDRDI8=;
 b=fkoGcQteC30tlpj6+K1gE/qFWVrPNPIIirzaxzStRLZO37Bx9JEM+kVl34SsItk6pu
 QfCmMVS87kyG8L5TfKzexdvJ2HEEyVos9W/sNoAiA00L7L0vtvHwwipUVUwwWsbTEptL
 VEGraBfRrzMFnfdCTee4y4KLFrE2qE0RYok0A3HHA0uUTM4XnVSofpEBNaat1+2BSOJl
 UESbwgwXvmGasispnve89VnnALpvzU6WyqhcIwBbDHhYYqJZ3D1ZVauidF1EpmtqRz30
 hciX/y/BzIEIosRvx4rLQNwMP8fGDGMlQhqMEJsDCgwdo6ehWeUXG9TY+vTcbP4B1cPF
 Trjg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1762511320; x=1763116120;
 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=YwJDYAiRAn67jAdYYlitqsFvX+Ia8OhH74XdKSDRDI8=;
 b=vgxpQeS+DrShUoX5fp860JsCnZJpvsZiwcfhCyWpAUVoGJrtTl1bgXmd/bSEr8vOGE
 FvEEpADvrah/h39q2w1RuJcArzXq4IuCLXUtMS3t1g7OYJYEEHD8mwSROiuaGu8wE3bZ
 xMIM6JCfzNfHXTVkRi/Naa7LS93FHd9Xxmh1yO1XnsdfhaEpCn6AdIUOGzCn7YEcz135
 d6DBpluPKd2TG9X4VzbqAVXKL9jbXFXXcNnqVyoIlvb3yQc7WiQG0LgAqh6dLKgI3Tt5
 rg86ShOMxKCQBA43h65Fcdi3ejr+j7fx1+snnfJB+/BynCKvJPnL2FhWPBWi92VUBzrC
 8wPw==
X-Gm-Message-State: AOJu0YyLqQsV0gfe6LyWZJZ40kJ9Oj70YXP8AMZojCQ2sKLxsAY25WGs
 fQMjKuE1GDfBcngC7Pjk1a34tXc8r3mb0z4/ddHMGML0eiCFDXjkqQV5C1NTNMO6u9ee2C3bAdp
 F4SVPsj6qvxrJ7DdFhnBX3XqPSWUVIXwlclgv
X-Gm-Gg: ASbGnctYjxCSMvg1aOcGMnTkZlBzEN8b0BiNaYV7Ar65/r7YWIodEX3cPkRfndBLSRm
 w+6e2lbZO4K1/4Pl1Z0RHFaEDEEz4ZQ0VwqHhlJtzQJDNX6J5FKgo5jjOLG/mOLNKca//PNqFjJ
 C4IVBV9rveUDzSBbZgv/znY4EOxg+yxJAfB4LiM5PwHPo3dilYUokakQxFT7e2S6ovTaRYvlbl3
 qs/7Mh2G/AKLXU4rY8cXSYpfMZ/oyj8J0ix6ZkSYN18Ne3HoWLuPNcp0aFCmA==
X-Google-Smtp-Source: AGHT+IHW5Xq83JxvRTyylYJSw/KExf1K+zsOGwuJ8djHklSt96YVJVqUtkGEuqH6x7FD1uXR3ZM+dOwta0TaD/lFhHI=
X-Received: by 2002:a05:6871:7823:b0:375:db59:20e4 with SMTP id
 586e51a60fabf-3e41e48a3b6mr1946306fac.13.1762511319904; Fri, 07 Nov 2025
 02:28:39 -0800 (PST)
MIME-Version: 1.0
From: Ray steven <checkscope.hyzc@HIDDEN>
Date: Fri, 7 Nov 2025 18:28:31 +0800
X-Gm-Features: AWmQ_bnUlKI9Ufo8nwiXRaUIsjX8iFBy_RMU-8Ntbz0T2l6sdKooFsNNZnWjAlo
Message-ID: <CAC2RF+MoNJYeON=uxcL9qH9jxZyVTAJhmnzQettwJqSyAmGGog@HIDDEN>
Subject: Resource leak in change_file_context() in src/chcon.c (coreutils
 Latest)
To: bug-coreutils@HIDDEN
Content-Type: multipart/alternative; boundary="00000000000022b6a10642fea52e"
Received-SPF: pass client-ip=2001:4860:4864:20::2e;
 envelope-from=checkscope.hyzc@HIDDEN; helo=mail-oa1-x2e.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-Mailman-Approved-At: Fri, 07 Nov 2025 07:35:31 -0500
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 (/)

--00000000000022b6a10642fea52e
Content-Type: text/plain; charset="UTF-8"

Subject: [BUG] Resource leak in change_file_context() in src/chcon.c
(coreutils 9.x)

Hello Coreutils maintainers,

I discovered a potential resource leak at lines 170-171 in the function
`change_file_context()` in `src/chcon.c`.

Bug Summary
------------
A resource leak occurs when `specified_context` is NULL and
`compute_context_from_mask()` fails. In this error path, the previously
obtained `file_context` (via `getfileconat()` or `lgetfileconat()`) is not
released, resulting in a memory leak. According to the official
documentation, the caller must use `freecon()` to manually release the
memory returned by `getfileconat()` or `lgetfileconat()`.

Suggested Fix
-------------
Call `freecon(file_context);` before returning when
`compute_context_from_mask()` fails. For example:

    if (compute_context_from_mask(file_context, &context) != 0)
    {
        freecon(file_context);
        return 1;
    }

Thanks for your time and for maintaining Coreutils.

Best regards,
CheckScope

--00000000000022b6a10642fea52e
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Subject: [BUG] Resource leak in change_file_context() in s=
rc/chcon.c (coreutils 9.x)<br><br>Hello Coreutils maintainers,<br><br>I dis=
covered a potential resource leak at lines 170-171 in the function <br>`cha=
nge_file_context()` in `src/chcon.c`.<br><br>Bug Summary<br>------------<br=
>A resource leak occurs when `specified_context` is NULL and<br>`compute_co=
ntext_from_mask()` fails. In this error path, the previously<br>obtained `f=
ile_context` (via `getfileconat()` or `lgetfileconat()`) is not<br>released=
, resulting in a memory leak. According to the official<br>documentation, t=
he caller must use `freecon()` to manually release the<br>memory returned b=
y `getfileconat()` or `lgetfileconat()`.<br><br>Suggested Fix<br>----------=
---<br>Call `freecon(file_context);` before returning when<br>`compute_cont=
ext_from_mask()` fails. For example:<br><br>=C2=A0 =C2=A0 if (compute_conte=
xt_from_mask(file_context, &amp;context) !=3D 0)<br>=C2=A0 =C2=A0 {<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 freecon(file_context);<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 return 1;<br>=C2=A0 =C2=A0 }<br><br>Thanks for your time and for mainta=
ining Coreutils.<br><br>Best regards,<br>CheckScope<br></div>

--00000000000022b6a10642fea52e--




Acknowledgement sent to Ray steven <checkscope.hyzc@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#79780; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 8 Nov 2025 10:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.