Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp300157lqo; Thu, 16 May 2024 06:51:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvk6+6j0mJDsLDRA9/9Ygwl2EemW+XBHUH9uJgIU5vV/KEDbV+jm5T+xBG6FPozZRNFJTsPRipti5F2sSMNurmH5bVgQkFXvslQCLbaw== X-Google-Smtp-Source: AGHT+IFIGMSr/5cgEZuJfaow0VPEtiGBf3ZF3ofNjiiAVlliI1TamegPKI4Q3pLXZPyW807DuUvv X-Received: by 2002:a05:6a00:139c:b0:6f6:7abd:a5fe with SMTP id d2e1a72fcca58-6f67abda9a9mr6093771b3a.8.1715867476854; Thu, 16 May 2024 06:51:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715867476; cv=pass; d=google.com; s=arc-20160816; b=s433dzoZyZAHZc3JqSRyRODCPy999RPW220JXR8GF9MGdAIsOvHn0qOZO/MHl9hIR2 ah+Cxdvnn0xNTYPlnSapN2W5vqih5UUA4gQjeRtWPz8TV8Fzf4tH4/a1h5XMVZDW/5Da 5kQiJOnvQkLIzaGXOHdNuNKSSOC8ep3+vsPtMlIphL64GLLEt/CX68hXg6pVR53BG8U7 4T36+oUFW1GAhsqc7CyulGQI2mOh1ewHYihP21trYC+oq4DgDLsLhz/tbbmscN6BBDTn ld69Rssq6IgBdXuJuZBAjwRTZA1RGOp3jqPNLms5Ab41bxbAswpwcFN4bS9RNw6dy2+8 BuzA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=SQHEyJ8uDtYpO/QQtVp1h7wbJotrVS1kqUcqT5Qlt7E=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=F0R80ko8FIkKOYlcCCFEvMQl2QblBWV1E7VCoIhXtmiTWdoPeJcEeLUbHYPqgJgiYd okRdiAaD8tGn57udLI0wABIiMjnzFuqwy6j8wMzXoxcgcUymNGPVu/DmQvge2NIb0+Zb RKZ6kIuiXnwdGPrWEqX1xYv1G4zML1222m87ok/413jFP6hD2DjiAEG8EiYC5uZuXKJp v1ukkLLpU3QM94aCmtgtRU498qbekjic6WeidnH+ZT89lffIcWRYInnG57SEnbO8thcw 7ccncDehyIq0rM/XZxvVv4nYsrUrKyTTA3qmFzf8bV0h23aYeBFPAAK8tIp7EJt8VyyP V1xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4724-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2a8bcdcsi15475497b3a.85.2024.05.16.06.51.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 06:51:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-4724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4724-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6EA8B284FAD for ; Thu, 16 May 2024 13:41:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8438E1474B4; Thu, 16 May 2024 13:40:58 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0DFE28680 for ; Thu, 16 May 2024 13:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715866858; cv=none; b=F0nznGkNbqZODVRgf59nAhBzmEnV1EhkGLaMVAiQGa8M28ttcq11r6wyBdB1ykfWofefBHnLwGV5VwWDGWcFEagpe4F0z8t5/Ac7wbkTsjS9lQH95iqldgnvUNIyBJ+PRWF2LN4ykevFI8VnrLcpiwRAT0Pire8L3lDgBYZxrZg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715866858; c=relaxed/simple; bh=rdh7g/ZcB2Ex0TyD5R4Wpsa+9G5LzF2ApinH5cm8B7M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nrnLDSyh69wMBMlVvt5e0CtjEDEVh63NbNueR5ZD1BTjBtxGHOkOFd/f9jvPmm7Dgd8oHEqijyLJtQYlchWr71VyS68/aHqj9XKxqSgG9T7gXtplSkbPS6d1+YINvAXfFv6jQ/OSm6qYp5MMDKG/GdIUeEyjCq1P5ZMnH8O263s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id B63CC20005; Thu, 16 May 2024 13:40:53 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ] obexd: Fix memory leak Date: Thu, 16 May 2024 15:40:48 +0200 Message-ID: <20240516134053.102475-1-hadess@hadess.net> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net To not leak "buf", we need object->buffer to take ownership of it using g_string_new_take() (but it's only available in 2.78 and newer), or we need to actually free "buf". Error: RESOURCE_LEAK (CWE-772): [#def66] [important] bluez-5.75/obexd/plugins/filesystem.c:411:3: alloc_arg: "g_file_get_contents" allocates memory that is stored into "buf". bluez-5.75/obexd/plugins/filesystem.c:418:3: noescape: Resource "buf" is not freed or pointed-to in "g_string_new". bluez-5.75/obexd/plugins/filesystem.c:440:2: leaked_storage: Variable "buf" going out of scope leaks the storage it points to. 438| *err = 0; 439| 440|-> return object; 441| 442| fail: --- obexd/plugins/filesystem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index f52927541bab..4887a0b8ac81 100644 --- a/obexd/plugins/filesystem.c +++ b/obexd/plugins/filesystem.c @@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, } object->buffer = g_string_new(buf); + g_free(buf); if (size) *size = object->buffer->len; -- 2.44.0