From patchwork Mon Jul 29 10:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 815131 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 283921428F2 for ; Mon, 29 Jul 2024 10:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250684; cv=none; b=DsWStpItJnA8Hq3XrvejEGSQkFj8S6/JBICFAX+8+44hye8r5jCkXJqs/pmOOI5mkEcC02VZsi26hlO4lBB9iVweB33U7JdG1/zCqQSz9yV4F+GiT+V7VCQaYy1BMF6tAIbggTs9n+CLppy2hjq14MAn3FwasTE2Cy2lYa0OSAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250684; c=relaxed/simple; bh=s7cZZRmxsDwzRd7DEaAWeVvYCa/invyf1ZkL3j18qD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6Z9Kw8Uf/EtiQasI3fYFcjIAugph1xJ8IsMAIuL6W+Cte8eXuKZYobyBmE9qL/vPDG27KYVbIuvSU4Sf/DP2QkzGQfKZP27r8DXSNifoM+/gEJ78Cu9J69qhiPKzqDSC0UgFJaFfTapthZOxGEgGJLeWudAqd1p4V77L7iHuIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SAuRh2to; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SAuRh2to" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4281faefea9so3033895e9.2 for ; Mon, 29 Jul 2024 03:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722250681; x=1722855481; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qYhIC7h0t54lRSrKMID9eYSGpD9atbKVN0wYx/7oAOM=; b=SAuRh2toMrzCglKheE4p7zWT70+BUOjuT120qAuNoyzakirWRNX5QER4E0H6PB1Inu xjPtmNR/FLpFVVBT3847p8mX0a6Y/zRdsL27yq1b54zHiDskTC7pwGI12b9o1innw0IZ VRgGZrqIj4nomE6wJKWXFlPKldgouzv/hItTIn7Mb7oFPoH8N69H+LFvUzN5GIflG8bU /BpXS46vyhVFYv79FF/Lrzd44JvGFwUmFEFnNsXnUgYWymLajMplkBPe5xyz59+3HN49 QNSyLJGPPLLrVVbirDHQcQKZ7anGHhwy2XgEJjvboND0RF/gU/LIeHuKXXC+yrqgseSs OLew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722250681; x=1722855481; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qYhIC7h0t54lRSrKMID9eYSGpD9atbKVN0wYx/7oAOM=; b=mbZyE+Bu1nwwCoONu4i4kyLROxZq/Od+7kVUGn8i673buhg4Z28Bw0oE+P176oU0ih ++IcxHgewkTotWubX1cHtkdwVhcr5QPxf3sE5iPkOZHR1mOc1wjFMKCqH9mR7XT7cRWx YTEh6/rkvDLwGMGhKY2UqfpF54UsWRyVCQO9SFXzLAl3sWLs5Xp7Oid+AMUK1aK7zhdV grtv9jogUf1buIxQ8Fn+1me2umNTowuByNE0T7RDhWWBYPUZdRdIS80bYZ53k/+5O7pA UxP2x7d2IoTB3BhMHP8lau0SAT5FLhoWxDF8z4ueDANbTMOO6w0bcp+oIsgo2hEnlUpZ wojA== X-Forwarded-Encrypted: i=1; AJvYcCVRQpZvwr4vrW824fsPdhvAQgk9i/BA7BdcjUJxBbXXnvdX4u50uXMaNLCfBL1qt2OinOLkfTA1nQg+PlIas0NF+6/UsQIL1I9X/A== X-Gm-Message-State: AOJu0YyGpwWdjqWl3Q8TW2XUgyUNwTmQuYjBLXdyzgBk3q6EsMdYBu5l JUg9T7NIzVFOgJtny8mjkQgO8bYZG/nnoKWPzRa+vH6Yyr77c5Nz X-Google-Smtp-Source: AGHT+IH+TjAXXUq7uQOJP5RbhAp0jgZiUnsHhIatqHciwABgZo65ZGSw6ClcImNxRKdJk2EwfRGXIg== X-Received: by 2002:a5d:6b85:0:b0:369:b7e3:4983 with SMTP id ffacd0b85a97d-36b5cee9e5bmr4390940f8f.1.1722250681097; Mon, 29 Jul 2024 03:58:01 -0700 (PDT) Received: from fedora.redhat.com ([67.218.243.111]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm11858068f8f.59.2024.07.29.03.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 03:58:00 -0700 (PDT) From: Iker Pedrosa To: brgl@bgdev.pl Cc: Iker Pedrosa , ipedrosa@redhat.com, javierm@redhat.com, perobins@redhat.com, linux-gpio@vger.kernel.org, warthog618@gmail.com Subject: [PATCH libgpiod v2 1/4] bindings: python: gpiod: avoid use after free Date: Mon, 29 Jul 2024 12:57:16 +0200 Message-ID: <3d8b12dd60eec59d4184c0bcc7d575b4eccbc22c.1722250385.git.ikerpedrosam@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 `req_cfg` variable is freed and then used, which would generate an error. Avoid this problem by freeing when the variable will no longer be used. Signed-off-by: Iker Pedrosa Reviewed-by: Kent Gibson --- bindings/python/gpiod/ext/chip.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bindings/python/gpiod/ext/chip.c b/bindings/python/gpiod/ext/chip.c index 28cf504..e8eaad8 100644 --- a/bindings/python/gpiod/ext/chip.c +++ b/bindings/python/gpiod/ext/chip.c @@ -274,14 +274,16 @@ static PyObject *chip_request_lines(chip_object *self, PyObject *args) Py_BEGIN_ALLOW_THREADS; request = gpiod_chip_request_lines(self->chip, req_cfg, line_cfg); Py_END_ALLOW_THREADS; - gpiod_request_config_free(req_cfg); - if (!request) + if (!request) { + gpiod_request_config_free(req_cfg); return Py_gpiod_SetErrFromErrno(); + } req_obj = Py_gpiod_MakeRequestObject(request, gpiod_request_config_get_event_buffer_size(req_cfg)); if (!req_obj) gpiod_line_request_release(request); + gpiod_request_config_free(req_cfg); return req_obj; } From patchwork Mon Jul 29 10:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 815458 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D96841459F8 for ; Mon, 29 Jul 2024 10:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250685; cv=none; b=GzJIhhqrsHSphKuYmKhjbUqZYcKCgQ9SmjX/q/OiQG/ReecS4xzxcxrXMGP5bQfzsI4d6FaJvGqPONaJgGv8hkcwfFRUyxyKAu3BQeWTaRNr+Ka8GuV6G4vqjHo2P/rYAf/lKrTsm3A2HZb+YCzouN1StuFv+y0Q81HgHrTCptU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250685; c=relaxed/simple; bh=CjcglEjj5maZHTGMPRYlVfVRYbNXXqvyJvzKiP4ymPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ETz7FA1qans0avuP2hb0qIa8yJCi8kvDRj4AEqNi8/ewFRQivhSoKZ5fsYPHfrDn/pVR1yID3EwpMBYhtk0tzPHbEQidPVp14Shrs2uYp+M8/XtUALwYtQPpd73Z1A/Z/Hjz+AoOPy+8qRT6LIyjClfqeSCH6TiTtBEWolH+M7U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dK8uyuwf; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dK8uyuwf" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4281abc65daso8627275e9.2 for ; Mon, 29 Jul 2024 03:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722250682; x=1722855482; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CwZGphjLSMzYA/JQp2KpfNJjuPVCH40cB4KhBRZbxPc=; b=dK8uyuwff090ms51dW0fo7GjarKHAyyA5lnFUnbA/oUG82T2zAGM4d4pernmgMbJ/+ r6Buoq1p96mtErhjnrG8WwAGgH0a/qdkmSgl5VH6PR/hEsrO1/2KO0s6QPJ6IxqNRME2 iR73Ve9tkoWONjKZ5J0MziOgFAojJc8zQRnh4IHYtqsg0AhFKro1NqohwYDmOUU6dVsv Hp+jLb+UEVCiFLU4LAlf5tupDJu3G4z2ViFmFbZl26mMmc88PannitvBSJq9mAMg1kZq WX+15bIG3X0REWRSwMF+OCD92X1bo+5OuFYgtgONf7WnOXd0qZqFWdZdUt+5p43pgabH bnwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722250682; x=1722855482; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CwZGphjLSMzYA/JQp2KpfNJjuPVCH40cB4KhBRZbxPc=; b=OQ06lBCJYq8QmdIBA9diytr+ct3pwd5voyua2Z6zrFFIgV8B1Jhgt+S04FuMMYWcgv CT/8ee2ve0JKWeIDpq8aMDyzqhE2ZQ4NH7YpwUXLnzqEg5oFnf8WOiWiFJDtf+sXSoMD 4TJXrL/gQg4mc0l9VSXNLthj+Vq1TSt2T/treKgMp63ubVMMdpXUqufRs4g1/YGP4UbS seFoz2cWE29um35+Kidk/N0+UJSQ6YIMENDZe8TgjRBljDTY3DEx/ObQ5t97mkyyaZ+1 ZggrkZr5cYhUe4EIrdjHA+I2hE+4KNxDQTViMbLPiYCt9uPYQwhCL0GEqh6RH42MCgco FEzQ== X-Forwarded-Encrypted: i=1; AJvYcCVNTOZMH2LB+Q77jpUmog0TrToP1ROtLTCcVVSyM5923uhZPcyNIFl3jTfzaCfUXjPq+juKDE025UbJUOno9JvzEcgMVwVkNvoqTA== X-Gm-Message-State: AOJu0YwvSxA1XApjtX0phB+dz71TAkBNCp01/u8Q6IclPTF6fD8HIZ7d 8noqjpicxmZ5NbqAbPPbGofu22o0Y0IRrDyIAiNT5xZJOS/4UNrlERm14S1x X-Google-Smtp-Source: AGHT+IFhO8XbluIeaB/uyD1tLl7H4Uyd1V0DOHMLHH8TVwYFcnibo2ettezgb36xK/1PmhW/3Twuhw== X-Received: by 2002:a05:6000:1043:b0:367:9988:7300 with SMTP id ffacd0b85a97d-36b5d08eb12mr4352019f8f.45.1722250681944; Mon, 29 Jul 2024 03:58:01 -0700 (PDT) Received: from fedora.redhat.com ([67.218.243.111]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm11858068f8f.59.2024.07.29.03.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 03:58:01 -0700 (PDT) From: Iker Pedrosa To: brgl@bgdev.pl Cc: Iker Pedrosa , ipedrosa@redhat.com, javierm@redhat.com, perobins@redhat.com, linux-gpio@vger.kernel.org, warthog618@gmail.com Subject: [PATCH libgpiod v2 2/4] lib: line-info strings termination Date: Mon, 29 Jul 2024 12:57:17 +0200 Message-ID: <84db7bbe2c84b2d880052a05f8b1cc123d60c2dc.1722250385.git.ikerpedrosam@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 strncpy() truncates the destination buffer if it isn't large enough to hold the copy. Thus, let's increase the size of the destination strings to add the NULL character at the end. Signed-off-by: Iker Pedrosa --- lib/line-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/line-info.c b/lib/line-info.c index 9f53b04..a7c6241 100644 --- a/lib/line-info.c +++ b/lib/line-info.c @@ -10,9 +10,9 @@ struct gpiod_line_info { unsigned int offset; - char name[GPIO_MAX_NAME_SIZE]; + char name[GPIO_MAX_NAME_SIZE+1]; bool used; - char consumer[GPIO_MAX_NAME_SIZE]; + char consumer[GPIO_MAX_NAME_SIZE+1]; enum gpiod_line_direction direction; bool active_low; enum gpiod_line_bias bias; From patchwork Mon Jul 29 10:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 815130 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843461459FF for ; Mon, 29 Jul 2024 10:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250686; cv=none; b=sDHHwZcKsxzEscNgjPvWMyoolA53fTW3dH0K4zMScuRMKRiZ9mUtljzfCyaBCDTTTPVm0Y0swGxO09fvp7J6add7XpT780M2u8sZ3sQ3RqQYNZSt4OxbSdQpLJooO5oNTXms7j76DAHTuYgfpiLYEiL/rC+mVpgCOMXy4Y3jyIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250686; c=relaxed/simple; bh=gLZCc9qmHpIT44P37m9AXhlucQrFVaG4bDCN0xZrXz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OZr6PrTOaYXIMcXy2Pr8e0J3TRNc5DrVXUNexIzF6tz13PL5gHRQ0nhYluHZFRBmkGwmcXK4bQhIM3/IZzw5j9OIGu4Tfwk4ddtmCFGFunwbyLd9FyxRUrJgCn719wS0rqaQ6HeUKIhWMH8hF4lnEhUGgUjxmqXyRkYN1axDn8s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RJzH3oKh; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RJzH3oKh" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3684407b2deso1234500f8f.1 for ; Mon, 29 Jul 2024 03:58:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722250683; x=1722855483; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QzSkaTDDvcXr4BKUDmdj7inT81xDIhuVfnzMx226u64=; b=RJzH3oKhLB4fC7fJFUs+8Vx7a7FBgdsYN+I/L97CCZU/KMrDgD9Qq3jYE6bgpzjSkO yE+mNLZRU4o2CQvfhCFnyODkY4zqgKnz5z5wefKd31wLUDn5MWUNOmhJmaarlwaaa2qx ronIHhGsj6XrxLYbPbOrZuW1EUtOOTnN9mGgHg6es032yh5f7omMSWiTeckoj3PyhaLG 4+C9oLLCpyzlLDfMvLu7HUelfmUUxCBzCDozeDxJiYabhGEV9+7HjVhj+AWQnyM7OXHI ToO0HtensGn6JYMxHA5vyThBqcfILTpsnSHPVW4QmncnKDesmCCQqBIgu88Sj78ySdj6 odEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722250683; x=1722855483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QzSkaTDDvcXr4BKUDmdj7inT81xDIhuVfnzMx226u64=; b=bwvj2w/tY0Dsv7K6HRuiTdl49p5C9+sVuDz3Cv32SLCa3FLbq7ToNqV3CeRC7PnFXV 3MDDbyqmvEmyo6WBCXjqhxkecK0fO/7BrE50soOYRfyR5ynQoVNedHRnFbPI5DZWrtQu 3eSoZjbLvJ+Gk4w1Nmbfcx7ZEt7KJP1H0IU/XnFA3Mx2FRdL3Vp1sJMKiS0PyUiAYL2o kQQdrCQBDY/jMHO/m3eUR80Z35ZQ+kbbmGT01wXRKs/Eia5Q8dYb7oM0xnJjpyR5oFOn i6xE4Ld06I7o/FIbQ8PGbO31o8c9qgXgooTyhcAu6IC8ZxWSaTy2s3ZJB5n84jzlRIAH jSUg== X-Forwarded-Encrypted: i=1; AJvYcCUAE53Tp3M+/2aQq7DebmQHrfLkTQh/ZlUBH2weJ+LeOVbMGY+jQuxGqXmzgTF34CEUrGdRd0RqVTC6qe6ptJR4VAIeDwb0q0ry2w== X-Gm-Message-State: AOJu0YyYi9o+8Hfs97XlQ7NBs5vAbnFcUB3xJNp+p55GgFi91S2EZ1ai EAGR6JcrA8Li7gWmdITIUZyBAeYcXUcnBmyRleXcjBw6v/5ifmGW X-Google-Smtp-Source: AGHT+IEdNDsRxucgXVeuLNZCnsJOTlABS7GVKRMfriJ7KhLTwfYejjgaII0duB9C3JOfOtb9dY2kKg== X-Received: by 2002:adf:e40b:0:b0:368:36e6:b248 with SMTP id ffacd0b85a97d-36b5cee250fmr4946168f8f.23.1722250682806; Mon, 29 Jul 2024 03:58:02 -0700 (PDT) Received: from fedora.redhat.com ([67.218.243.111]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm11858068f8f.59.2024.07.29.03.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 03:58:02 -0700 (PDT) From: Iker Pedrosa To: brgl@bgdev.pl Cc: Iker Pedrosa , ipedrosa@redhat.com, javierm@redhat.com, perobins@redhat.com, linux-gpio@vger.kernel.org, warthog618@gmail.com Subject: [PATCH libgpiod v2 3/4] lib: chip-info strings termination Date: Mon, 29 Jul 2024 12:57:18 +0200 Message-ID: <1d7cf79edf75ef77baa56091852be90e2359e572.1722250385.git.ikerpedrosam@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 strncpy() truncates the destination buffer if it isn't large enough to hold the copy. Thus, let's increase the size of the destination strings to add the NULL character at the end. Signed-off-by: Iker Pedrosa --- lib/chip-info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chip-info.c b/lib/chip-info.c index 87fd9e7..478cd62 100644 --- a/lib/chip-info.c +++ b/lib/chip-info.c @@ -10,8 +10,8 @@ struct gpiod_chip_info { size_t num_lines; - char name[32]; - char label[32]; + char name[GPIO_MAX_NAME_SIZE+1]; + char label[GPIO_MAX_NAME_SIZE+1]; }; GPIOD_API void gpiod_chip_info_free(struct gpiod_chip_info *info) From patchwork Mon Jul 29 10:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 815457 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AFC2145335 for ; Mon, 29 Jul 2024 10:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250687; cv=none; b=JomUQs0MAkcnBKGBF+vyTxydKUiNM1idFi3q1ACpcKOqZ/ymlKCC52j8rb5Y4nENAtr6RlOfcwwWeii9EHuHcTB6HASZjHnkJNFyzzllSOL9VrWn0PmWTAanu5q5H1W51Q2mNaFIE9DwrSIDoz82xInh7KlP0JStvZsQUoWNAcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722250687; c=relaxed/simple; bh=648WPwSypI01dozL3GPxYcKmchkxukmUVr2UadNI6VY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ngnGSAeOW28LnEliNY3QR/AMyOTBcQtVzyhJeUV55WH/6zfumrMJrZzGpTpb64j4o+2Qh0klHOjhQh+UAd/5sJGQYS/wPeKfey3GALJbpMhhZMja853X+akSchk0zb8T5W5NuC5u5JisNsfMrY+/jMYX5bxAXDany/4PqgeLiPA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KU9B4g0Z; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KU9B4g0Z" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4280bca3960so15639015e9.3 for ; Mon, 29 Jul 2024 03:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722250684; x=1722855484; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T6itGH4T9eUxyrVDIKCTbm8yTTmvQOv43V6XixxxIn4=; b=KU9B4g0Zy9j0QFwjBdCZM6ThG0U2YqsXVrVPWcKLc+EF051gqV/cEWVxXl3Y7qVqPB DBUCgVh/mr0XldeRPUDpYaTO/3AFbRx9LyIRNNQb5LzbuxqlDmMqE6imKuWZaifaRegz 3PObaqtAbVTq/ZIQpFoSHqwaCfo4cbYGdF9GdGwctTez8ZWR0+JNHmEq9lWL4yU7Wl4i zh3bS4Rv6dqq7auXGPL31DAQegnkmZ+IsZzmF+emiir93uaiXh/Ojt4sgtp8covJdzT3 lghJ69bh9Kz5qXoONXF5fgOkdhiAZ3KgkwgjkFUD+FBpi1Ae9GFHe9FHfEv1LlCLTzFB rvuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722250684; x=1722855484; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=T6itGH4T9eUxyrVDIKCTbm8yTTmvQOv43V6XixxxIn4=; b=OXoTvZm7FHOp6TXnm4ravzW2GjTLVCmJye4ozLyQDbz8h4EhYDF43y/Y4jZI48G3Pm OCvRSP9OQ4owD11wYgxlAszKSiRg5kSHUjCREf0MuMkRD7agdtB+w823LzYt5wFzvpjq c5w0KF6dR8HHTDNJhm5NnGev2X9Ej37z/hiNx/ZoA64BqY5bHvivn8UU1y6YKRpKSnCb 08qcjOUTTX+xk6Hl8adkoHoNqQWCay+aUXn9b4J85mmjudefZsEJS2i4qRRJP/BwDLbt pXmLqOGY6khjomvIbQRA8xzPn4RRFaQ9LjWaeT4P+PZXNTc+BE3vo3mPLFvZJ1viTuYz dbKA== X-Forwarded-Encrypted: i=1; AJvYcCUal7SwZU+WJr0/ffDWBVxetCdtwqLsKU5xKy/8ZnxE1Nbt35HsdDpoZ97akQWAlqYe72eR5cMXO7neOaZDqhFt6DrrG1P5VbgQMQ== X-Gm-Message-State: AOJu0Yz38GY1611My2j09m4H+YBmnq4UHsZz0KprQ9mSfQE4DuWi9/iF eEZwZHXnPih8ru+h9pB92MNlM7MhLHzPPupC+VAX6A3aexl9HDKU X-Google-Smtp-Source: AGHT+IGnrunNf4IEPH84qImEPyBm3e2kMJAZ0S47dYkkaQnZe5AXkKF2xl/446JFsGP+0m39QODTjw== X-Received: by 2002:adf:e74e:0:b0:367:83e9:b4a5 with SMTP id ffacd0b85a97d-36b5d092cc5mr5370814f8f.49.1722250683653; Mon, 29 Jul 2024 03:58:03 -0700 (PDT) Received: from fedora.redhat.com ([67.218.243.111]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36b367fc8a7sm11858068f8f.59.2024.07.29.03.58.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 03:58:03 -0700 (PDT) From: Iker Pedrosa To: brgl@bgdev.pl Cc: Iker Pedrosa , ipedrosa@redhat.com, javierm@redhat.com, perobins@redhat.com, linux-gpio@vger.kernel.org, warthog618@gmail.com Subject: [PATCH libgpiod v2 4/4] tools: free to avoid leak Date: Mon, 29 Jul 2024 12:57:19 +0200 Message-ID: <418b4fa7b6279b15ea10936d65ce45e01675e491.1722250385.git.ikerpedrosam@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 `info` variable is allocated, but never freed when the loop continues. Free it so that it isn't leaked. Signed-off-by: Iker Pedrosa Reviewed-by: Kent Gibson --- tools/gpioinfo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c index 44d1c8c..d5e4751 100644 --- a/tools/gpioinfo.c +++ b/tools/gpioinfo.c @@ -195,8 +195,10 @@ static void list_lines(struct line_resolver *resolver, struct gpiod_chip *chip, offset, gpiod_chip_info_get_name(chip_info)); if (resolver->num_lines && - !resolve_line(resolver, info, chip_num)) + !resolve_line(resolver, info, chip_num)) { + gpiod_line_info_free(info); continue; + } if (resolver->num_lines) { printf("%s %u", gpiod_chip_info_get_name(chip_info),