From patchwork Wed Jul 17 11:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 1961598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=b4g9wFR9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-gpio+bounces-8243-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPDTF68Hfz1ySl for ; Wed, 17 Jul 2024 21:38:09 +1000 (AEST) 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8B3111F21233 for ; Wed, 17 Jul 2024 11:38:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6342E17F4EA; Wed, 17 Jul 2024 11:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b4g9wFR9" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 B5D223BBF1 for ; Wed, 17 Jul 2024 11:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216281; cv=none; b=txvUmpLpC+WuA223I37z6sR/pPbdRhOTZC10xAxmGLM6VvakflRL8LATcPoRZOQhYaBpPW6zjP5aqK87xzkdAmf+rIQYUQhlrv5HngEmU4RhxLuE0LcGSMf4IPslrvOdANAHNkw4J7wMxySXhRwPr0QZNdPmN+zsiU/lYv6KB6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216281; c=relaxed/simple; bh=nDaKwEhGWwlT2me1BhTjil2n1UNUurU/Mz63ebnFIKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pTH2oOweXIvGo5Hh/dAhCZiheYRR/4FFax0wQwgeFeuYP4xfMV/1psVYmBexz+V9Z7JKcUb8kkpCO5uboQ2l07hrKJgGYthkEbB02g1KTizaCOukKoObfRQsxrW5Li71V2OLZYlh355q6I4T4/0FLlIecjEz8W9vdMsXeUcWnS0= 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=b4g9wFR9; arc=none smtp.client-ip=209.85.208.182 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 Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2eefeab807dso5645651fa.3 for ; Wed, 17 Jul 2024 04:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721216278; x=1721821078; 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=q6kXqplDLSO/w59wyHz1CzCg9tivFVEXGEWclRYM6C4=; b=b4g9wFR955dXlrfnUkkGW7+U7muqn6axj3mNvLxeTso9tXMDUbfbG8JJUJKdC98DUx wAeaURDBaOa7Ds7J1PQbf2WnK2vY7EMdfXjFsQKXQ/SVicL0KA5z9g9SGg0+rAiSbwBt es2wTkw+904gvjIyLJOC54/IAvHYVrSxC9TteCDeW8jr2Mt3z79AChg9eKR+KfUnq71e ojB/Am0i4OMDm2TORYAwNiAX8siWO8KHj3mYI6W8nDUfqyt1kGgizwn7zLNt9xHaAAm8 2IV7IrPPA50o0ZzzwgmU0RthNCr1pPOy6yjA258UFBdSHk79/ZOYPxCH95sYTpbHZFW9 t7NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721216278; x=1721821078; 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=q6kXqplDLSO/w59wyHz1CzCg9tivFVEXGEWclRYM6C4=; b=PQyUuJEMqZMuRmUsMywrIwb2lCwOniHReKPHRheugRlmk346MFqAy+WTw2rKsHmVDv hnZ56HgUsuScrHt4opYq7DDJtezHmh3ohw+pY3AEkUPK94AerJhaU0eAface+t4U4BbZ dL4cxORpSs8q1kbpLf7ttn+WiDfi7g7HrilCW9Nce9ELYQOxim5vMxLdMwTBsdr2RoqU Ccc++wPoX/jSQn0DTyusePAHJT+DZc2hqyLmxjXonrvXSpCND7jnN2d6s7vP0x8MYjWn AGG0W9kLN9WrBVZAQJZ8VPGiTwEr82q853lGLD7BCzfSwhpdWVdwcWvWK2Mq8PnIAPL0 osJA== X-Forwarded-Encrypted: i=1; AJvYcCXETPjDaseqjHnwobjjbyCC/NdjYLyzh3qyGPwwLxAqpuUbxnrXZO8X7S/ykfgedkNdBqi6MA3Nkr+fqzO4sbYNYdrPtORQOq2OKw== X-Gm-Message-State: AOJu0YwV10vf+heff76hx2/1LpEENyNIQUOdanJ+2hLNT+IElYm5u+Md ZY1cPRSgpWaZpWLm6xMVv0Yh5XZdg6vhFGUvZGGCGfUF0TxMTS3nC5xMihCF X-Google-Smtp-Source: AGHT+IHurOR6hYVY6XPcdgzj1rZWohIhBSymJBZaXFYmnsKJJQfN/3Q1vJpqQSJ0sLc0nlu6uQzjUg== X-Received: by 2002:a2e:7c17:0:b0:2ec:3d74:88ca with SMTP id 38308e7fff4ca-2eefd0bd59dmr10149901fa.25.1721216277799; Wed, 17 Jul 2024 04:37:57 -0700 (PDT) Received: from localhost.localdomain ([67.218.244.73]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5ef4617sm165705635e9.41.2024.07.17.04.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 04:37:57 -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 Subject: [libgpiod][PATCH 1/4] bindings: python: gpiod: avoid use after free Date: Wed, 17 Jul 2024 13:36:41 +0200 Message-ID: <250744d18d2d9f067daafe6c1ed426e75bf5b76f.1721039339.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 --- 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 Wed Jul 17 11:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 1961597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cRrPZK6c; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-gpio+bounces-8244-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPDTD6zzrz20FF for ; Wed, 17 Jul 2024 21:38:08 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5A9F81C229BA for ; Wed, 17 Jul 2024 11:38:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADC7917F4F3; Wed, 17 Jul 2024 11:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cRrPZK6c" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.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 E717B17F399 for ; Wed, 17 Jul 2024 11:38:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216282; cv=none; b=egY/EU7sM3fcUj0khoJJIgcqTWPcRGQScQk5DtmGTFicAoFzZiEhDTcvdIqyZpmEuotXGMBfIZitkJ5FLDq2xjzaoGx/FBH0xrLbPw16szzZ20LVRxlO8iJLLLUNh87UopiG1VoUitxkk4einlk/U9H4DjER+pMRRQd3KpbGTZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216282; c=relaxed/simple; bh=enwmZmuv0L96caezA0J96IDUGnYyrKmPtVfarbKLP1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ya1/U1UhC7Obll24xNh/KL7YAWWMwSorgRAQr6WH6pj5QSNMhlM1Q+Pm4SeZpYbhRLhlvhacEG96Nl+fz0zYAilcuXmeIPde53PPWGLbsbEq/Z5irD7TgI4WS17rFp1kvPhuqElR2kERb6XLvK5SXzIoxdbL1dSz8HnwgI/TUyM= 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=cRrPZK6c; arc=none smtp.client-ip=209.85.128.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 Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4267345e746so46895705e9.0 for ; Wed, 17 Jul 2024 04:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721216279; x=1721821079; 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=la8KaLTUQo/ZMk9KONJFFAg0PJ07uCvXL6Kih2dokyU=; b=cRrPZK6c/RS+Joh+8OnaCxnBsMNV8rmaIAeZ3j6xDtqvDVmY11rC2grqbm4YzD4qxE qbkmZHmAMFmQrYCgqQbbnZ349yhWlBvIyI8a1tpLIZ/X+XT2ESV09BBiAZujwLQA3nOz tEbUzA20wzwutETDjIY0NohhlFI68fcvgcU7jdymXyTiPbjlUCWTS9Pyoo7GRgyJlaBp R8Gt7vgFi298dX8EJI0hN3M94B5ZLoU7ZU5q0qM1Kd1QAk2zS4lAzfgAP1gbn1Mt+7yo ew9GFlap6S0mil4xC9KYu2zXO9WP7b6f/4OlXmValRm0uv20Sf6sbuSQT6O2wrX2yD38 0f2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721216279; x=1721821079; 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=la8KaLTUQo/ZMk9KONJFFAg0PJ07uCvXL6Kih2dokyU=; b=DWDf+btgkLjIfSSQZuzvPwR6B6RhLvFAMvDUFmd9iOs9kcf+655yH/bXUQ2Qf5hDFa 1/nrBJex4MGZ+T711NRc+QPhixITWFiVpf4E+GeQnaqWToNgHZfoDn6MortDeTVvEM06 F2gpGOrKCvmzs9i6TKGLuLmqfjTVne+A9qNIaOYI66mtMFvMvtKL4FtSq1oxyLAzWw1S LXiDMCc/+uVqPv9BtGcvGriHKNe7AnIeL48p7l2OTFSReIuq99UMyk58kO1VqtfBJSmb KfGTcklemjqlIAhfSdvT4dGMbX2L2X/watjrFxSTnWCIj3HpkeYV/SR0q8rDRIPv3DdO z14Q== X-Forwarded-Encrypted: i=1; AJvYcCWMLQJ7aKzQ9g/FWMnXt08Spz5J4xHILn3aLqSVZW/mIzXHXAJ9I31H2m9iygm21x0oKNu0g1B/89lN1Eme50gXwWW5rXot2KGf/g== X-Gm-Message-State: AOJu0YzKY0RxtzDUladp3Qada3fa6oF//Wbk6gKte9oSbmv5VeoE1kzi dwAcw+ABhFZbORBSBk6dVsL4V5yf/f4OrGHb3fOl3bIWVCZ8qjhx X-Google-Smtp-Source: AGHT+IGk1j41e/17L4+jt8Koxf+RogPXySfxsiLPrLDRjfdxx8p3RLqxIV4IcL2R4z5xZxSPWQqpYA== X-Received: by 2002:a05:600c:c08:b0:426:6f15:2e4d with SMTP id 5b1f17b1804b1-427c2cc27f0mr9100335e9.9.1721216278954; Wed, 17 Jul 2024 04:37:58 -0700 (PDT) Received: from localhost.localdomain ([67.218.244.73]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5ef4617sm165705635e9.41.2024.07.17.04.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 04:37:58 -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 Subject: [libgpiod][PATCH 2/4] lib: line-info strings termination Date: Wed, 17 Jul 2024 13:36:42 +0200 Message-ID: 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 terminate the strings with a NULL character at the end. Signed-off-by: Iker Pedrosa --- lib/line-info.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/line-info.c b/lib/line-info.c index 9f53b04..2ded9ea 100644 --- a/lib/line-info.c +++ b/lib/line-info.c @@ -148,10 +148,12 @@ gpiod_line_info_from_uapi(struct gpio_v2_line_info *uapi_info) memset(info, 0, sizeof(*info)); info->offset = uapi_info->offset; - strncpy(info->name, uapi_info->name, GPIO_MAX_NAME_SIZE); + strncpy(info->name, uapi_info->name, GPIO_MAX_NAME_SIZE - 1); + info->name[GPIO_MAX_NAME_SIZE - 1] = '\0'; info->used = !!(uapi_info->flags & GPIO_V2_LINE_FLAG_USED); - strncpy(info->consumer, uapi_info->consumer, GPIO_MAX_NAME_SIZE); + strncpy(info->consumer, uapi_info->consumer, GPIO_MAX_NAME_SIZE - 1); + info->consumer[GPIO_MAX_NAME_SIZE - 1] = '\0'; if (uapi_info->flags & GPIO_V2_LINE_FLAG_OUTPUT) info->direction = GPIOD_LINE_DIRECTION_OUTPUT; From patchwork Wed Jul 17 11:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 1961595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iYmlONO0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-gpio+bounces-8245-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPDTD60skz1ySl for ; Wed, 17 Jul 2024 21:38:08 +1000 (AEST) 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 102E3B20EDC for ; Wed, 17 Jul 2024 11:38:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E42D817F4FD; Wed, 17 Jul 2024 11:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iYmlONO0" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) (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 1F2963BBF1 for ; Wed, 17 Jul 2024 11:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216283; cv=none; b=Ftn5ooH2vA08VzhOCQOSQg6tkRalqeoaH6lEgqjyGUcyh74y7IKAGWGjUyt0cR3BnWXNBzn0OavVd2V38pwH8i3BdlHxBt9OKRvSOF1TrAFvqmZc65FUh+LqwL6htW+/Hykf1FMyPjj2SEE+6d6WXfwebxd9b4HdRyAA873BpTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216283; c=relaxed/simple; bh=ILKUmaQG9KQlC6WL68YOR6O9XEyIOCMsN3lUg8ieuo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D0ePJQY4/BPOtQtXh1j+0um1z7JsdwSk+zt0xTzT5B/R6NPHpOMzHoYXTXiXYSbLctckT3IpjHfQNW8k65/c2ZXQN50lX9YuhdhX/XB8VlcH7DeVagO8hYhtKEniP93LOc7C7VU1d+RkBjkLS4pqx0JWGAfSmj4+Us18+GAh06I= 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=iYmlONO0; arc=none smtp.client-ip=209.85.208.177 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 Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2eeb1ba0481so94049431fa.2 for ; Wed, 17 Jul 2024 04:38:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721216280; x=1721821080; 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=UQZT6M6FcqQ2Li/Ber5DmgcsjI/eghY/46+HVQwLP8k=; b=iYmlONO0yyvMkKqlZe51LiEggM7PR0BZfuK+4AN09z2SM/8+zQxhSRjr8nVVpMGPpG TAASG8P5Gp8u0IL88WOFiArL4MitaygVg+CU34rAMhe28ikWD6IH2NYkhGVcw7W1B7gY WLA3QVFAIvEqX3Z7joW3Qj35EMwHPyo4ESl7nO8FNtexPZp80JTj0A5TZgOkQPd95luo vmJm2fUpbHaGDuHcnv+IhC3lZpG5Ql5IrXgaUBgR9B8/UXAKZRtkyUkl50IU/XUgfIuw x3vxNY9nT+dyZ/1ZbBf2QTh1eqlYGpXQ01xciuerkGmWYidRY2ZsLA9rELDk5iwSgOuo 7yjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721216280; x=1721821080; 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=UQZT6M6FcqQ2Li/Ber5DmgcsjI/eghY/46+HVQwLP8k=; b=Xv4kjXDd3jm8KVlOr7KfdjALJ4JdbWd9V9TZCMUX8FPbbaC0BFJvmm9PhWN0/RNJe+ Uq+8Wfd6X/jGEEZJu4IgVGycz821Y35zuEIRu7FFC5YL+Sh5nMvTHZLCD35Ih6V8L09J Kvb9X7r25Pw2MzKQkBfEKkXkVMvezFlPJXXwxiFikWkN8WvJhB0Jab82LmRM0Fgzx/9U RBkEl/Ow6FnKjGs8fXkE+2y89F/maSmrxOY3ghS8p99l+dDqNnortT1qg8VKTs4a7XOJ /K+Gw5E9LeuWN1RwIDspKIrOJVV8M3+nqZuA8Zlai/7l2K8VfYaW45A2N+HLK0StelXB 5CnA== X-Forwarded-Encrypted: i=1; AJvYcCX0JxOykAuQzOUeJPS1oxL6PXtted7Roqi6WnfKzhOVXosFAz4WxmiwhHrhoPDH0GBvPtv05Wu8KXau1jvn6Gs60XNXO9d+QNyhNQ== X-Gm-Message-State: AOJu0YyllxIIdAv5omgNjLFgjuXjmNvwyeiOucQfsHo1d0aHG6SG/Cpp Ek6WK61A0+Gx3/NvYyWZS9Yn2pCOPqMQ63wDFbcJG2FABQdnOJS+ X-Google-Smtp-Source: AGHT+IE77woKCSfCHYxjYQQPz+Af69ZcmfSIxgOA2mc3sq8zSlDCwKc72Zwgc6ffE7yGdl+sQXWOJw== X-Received: by 2002:a05:651c:3c7:b0:2ee:7255:5048 with SMTP id 38308e7fff4ca-2eefd158035mr9395511fa.48.1721216280027; Wed, 17 Jul 2024 04:38:00 -0700 (PDT) Received: from localhost.localdomain ([67.218.244.73]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5ef4617sm165705635e9.41.2024.07.17.04.37.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 04:37:59 -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 Subject: [libgpiod][PATCH 3/4] lib: chip-info strings termination Date: Wed, 17 Jul 2024 13:36:43 +0200 Message-ID: <275f51e932498959d57ebc5bf16adc90bb7b5967.1721039339.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 terminate the strings with a NULL character at the end. Signed-off-by: Iker Pedrosa --- lib/chip-info.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/chip-info.c b/lib/chip-info.c index 87fd9e7..2f2523e 100644 --- a/lib/chip-info.c +++ b/lib/chip-info.c @@ -57,7 +57,8 @@ gpiod_chip_info_from_uapi(struct gpiochip_info *uapi_info) * GPIO device must have a name - don't bother checking this field. In * the worst case (would have to be a weird kernel bug) it'll be empty. */ - strncpy(info->name, uapi_info->name, sizeof(info->name)); + strncpy(info->name, uapi_info->name, sizeof(info->name) - 1); + info->name[sizeof(info->name) - 1] = '\0'; /* * The kernel sets the label of a GPIO device to "unknown" if it @@ -66,8 +67,10 @@ gpiod_chip_info_from_uapi(struct gpiochip_info *uapi_info) */ if (uapi_info->label[0] == '\0') strncpy(info->label, "unknown", sizeof(info->label)); - else - strncpy(info->label, uapi_info->label, sizeof(info->label)); + else { + strncpy(info->label, uapi_info->label, sizeof(info->label) - 1); + info->label[sizeof(info->label) - 1] = '\0'; + } return info; } From patchwork Wed Jul 17 11:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iker Pedrosa X-Patchwork-Id: 1961596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dh5jCxyX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-gpio+bounces-8246-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WPDTF0PS5z20FX for ; Wed, 17 Jul 2024 21:38:08 +1000 (AEST) 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 A6BFB282F34 for ; Wed, 17 Jul 2024 11:38:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6083B17F4FC; Wed, 17 Jul 2024 11:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dh5jCxyX" X-Original-To: linux-gpio@vger.kernel.org Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 BE90B17F4F4 for ; Wed, 17 Jul 2024 11:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216284; cv=none; b=MJZHxyIknJMasZ59HtzMykaxe9LGHteX+hS+OATVEU++2YEuekLMcSq/Pu7x44x7HuzfLdeRlobslRJ/Q61751OZ8bctZtj7LFa6YEnhg0UTfHgS5bZzkYSYZ/2wv7uuDT0AZywBKrI/e5OCEuzTeuLljmN2Q/ipfvhA0LHoBHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721216284; c=relaxed/simple; bh=28uHdYU7bou+GcCZWKwcmy7jqxAWnvFc5h0JxdXaHXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BTgLqpQDmb3as5sm3HJpQCVsmQU7CXKqLVkViulHKx3+W6d2MGQmNJ2r8XDF5xF3tOJPMnchRJQNcjcbSaNrx1kKOdLvEUBKa4/pMCxcwWDm7pUzi2bMeEWXS1iHpgNYYUcQm+BUWbwNlR3D91y1d+AVqPhL0kRJakXsS0QvIf8= 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=dh5jCxyX; arc=none smtp.client-ip=209.85.128.44 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 Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-427b4c621b9so19942235e9.1 for ; Wed, 17 Jul 2024 04:38:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721216281; x=1721821081; 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=Y0j8GcEh/iFICfcRQgHpVxnMyyzW5tywJ0dsUXrPo9U=; b=dh5jCxyXpUT51Gr/GOrYYKJMQphKcU4yHGQYtqXpeA53fQFvMG1PTky0fNTXn1bgdp vgx9s/6VXbxqHZEFCWudR6SBF27t+GbRi2KM+0Qp/SjFHToFS9JJhn3Na7ihrwtBAWmf Wet4MMxfkkUsuQ+2WN5lDqiVM0orVQ682zInn20BmPAQtLF6VZobOi4lMtYIxtQLTTFF fbDf2Ji9TCoLXjv6HN5l8JfeEmjlEEBihLQZGhIUsk8uOxNy0gKrrDL+Bb8R4Rkevy2U vcUN+R+tq1LWMuCeTMbYwX6lHx0njQBjnm2P24WP16Kj1B+sN/Lw/0dBgn/MjLABQQcv SJKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721216281; x=1721821081; 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=Y0j8GcEh/iFICfcRQgHpVxnMyyzW5tywJ0dsUXrPo9U=; b=owFSY9yyHk/z0l0QGlN/7ceosrQtLqfvlU0gkSpNTatUbU4ozW0gH6YXOBVNjh+kvS VYZos2iJiuHj7iw4JuFKbFNArNDJen1OuaXwwSje8SWkaurGCdOVH4gv/6sDVtLvYrhd /TkOmWbq6oKw4XUTF5N1ApS8/aWkIryKs8t8M+uQgZ62M25mBr7lgz7uTsPSCy5wts6c 3bQ3SN7scSW5CueeBtrr16+BwDmpeV9GXU7RyPoIA98LP1XHG/kVXaqMpNc80ly/TexW xZ1MNIA9SNNkHu6/CSVJs71dD+99Qq/QhuBxI0AzoUYW5ju1RFh9Uj59sRwAINeHIXXt N9VQ== X-Forwarded-Encrypted: i=1; AJvYcCXJtQR9+T9mW24G9ZHbAjWKOY0HWMQMVdHE0h9sjqqbY/OVEXEYExBft3e3FTFwlLhArS0D/rSP4XfrgUNgTl0jFT2zeJo32otT6w== X-Gm-Message-State: AOJu0Yy8fUwdA8LoJ9GeNB/r0juEJJX5r2AQISm7EVGY8Xy7p4sIEo+x CC+aByym/w0JsuokF5+UyBHvIOlBI5hMRHkBKYSt7D3p9gnCBiWe+jXPmKMX X-Google-Smtp-Source: AGHT+IEJFpModZFeoiscwJTh7+SvIx2I1Shl4dLM2Fnmwz+CGz0u247LK6wdhFghZqJbUb4LIyIK/w== X-Received: by 2002:a05:600c:4f05:b0:426:67f0:b4eb with SMTP id 5b1f17b1804b1-427c6ba4cedmr213645e9.2.1721216281139; Wed, 17 Jul 2024 04:38:01 -0700 (PDT) Received: from localhost.localdomain ([67.218.244.73]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-427a5ef4617sm165705635e9.41.2024.07.17.04.38.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jul 2024 04:38: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 Subject: [libgpiod][PATCH 4/4] tools: free to avoid leak Date: Wed, 17 Jul 2024 13:36:44 +0200 Message-ID: <6d1ebaa522b58e8cf7b990c5fff3964971f4a443.1721039339.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 --- 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),