From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) (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 5365F37BE6A for ; Fri, 8 May 2026 16:02:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778256177; cv=none; b=RWn3Id5Jcz0FiWgT0O1XLNPtjz8gPK6Aw6JebnffW7COS2ev3AWfm1hRF3+1ItBofv5zezmkPeHKwO+b1QKfKHcbe7Tb6eFn+kbZAuk9GxnLEE5SkZSLiPKnpdrgf2T3CUDikgEJayMe05Jrnta8ZgPW+zn/9CRWkmXoi+eeK8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778256177; c=relaxed/simple; bh=39soWo0N4Yj6sXK2uSFvuyS6lYjiGWAqMOxp0m10AE8=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=XqIb7iFoq8qyOKqCskleG2XCbo+BWSADeocxx11ERRqqMkTrWGjlIeYWUv94+OL0i3ZBoT9bXQnNz+dxYFC9zSNMlOWK1Sye2dugM/bE8hqRLx+FafiCP8eynwGv49UO793YN2v7ZIKdk+fcg9AtiyEx8ev0JIErxlRGWDadAWA= 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=Zs8krQgU; arc=none smtp.client-ip=209.85.128.171 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="Zs8krQgU" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-7b37d84a6b3so22298157b3.2 for ; Fri, 08 May 2026 09:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778256175; x=1778860975; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1o3nVBrC6L9H/RVYpMEYGhUOr4iFE+C6Tvg94gHGLP0=; b=Zs8krQgUgHscF3o/4OyKTku3xKJyJHXr5Qv1ow1VbDjpOAJIpzIWX9Z7P/pRIX5HyG 3sShfXeCOLmX4Ufhgc5wdWiy/E/DmK5MmgTW6oysjh5lu6Ga/7rB/X5O0iOvxRaMgwp7 364znSpl9VxGFlK9tuNsZKCsVewSbrDRkzvUYQpLP7pTvYHJSlpObv2e7XrNvnurEf99 AyUyslqPAWeh2960l0TTBeAvBV2K5lV2rLEXsRzzLP5mnhIiH6jHZyG02MfvZKrZnTsU kdC1xjT/S8DNcILLJsAR5zPIm+k2VGX3cE3Ffjt6VA25NDEWLUuU+4WWglAYYF2w6qM0 749g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778256175; x=1778860975; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1o3nVBrC6L9H/RVYpMEYGhUOr4iFE+C6Tvg94gHGLP0=; b=bozGyIQDf3tv+2gYLQ5M1XsWS629sLGtytbVHa5lK+o1FPdb+RTgzzBIbGJFNHJAtm lqlCK7ryN4CluvtE+jsf8BBSQdCo1CBM1j90h0uyCixeycWwdj+p8Dg57tDZf9Eq/twt eD2osolUPPgRGmVIY6R0iNv2n27x9WrmTB8TH+l1EAe4jMZJW+6Vw2GUcyinm/sfB1T6 aI7db3mubDfCiDax7OB+RKTpYWleqJNzUgqQoOaYUVCHtE8PRfh9O39WQnv6CCN2ZTY5 xDH+hSRUdSw7Jh4/+JSOS0jYDMi4hN/wFYj2ZqTTQxKxlWlFvpBJrr2IFgJvtQ8/QpqC tsnQ== X-Forwarded-Encrypted: i=1; AFNElJ9QUwuSEBOh+Q7oWCMjiofiaIcyseLi8OTgYxyww1C0cp75syYIrPZhXaTc2593/QxYbmNdk6nAu+YYHcw=@vger.kernel.org X-Gm-Message-State: AOJu0Yzy51gGoOwos9GW7LQUdNXgfHUpzaw676hSJdzaEV+avspmc1dJ 7nZnyvVeazzZl3OfUp0bsctXdSqOuUDgvHtxTiSuXCEE31nH/xbxex3F X-Gm-Gg: Acq92OGKPNYRZNe970rcFu+ZHNo09keZvvHBTfNb8b6grxMWdKI5SIpZ9M4g7wounj8 RtipCDNmv7kwJuZmvtdi5suEbLpn6kgpggg6xG1yhqhPUZewrGCENyLE3N+RBTqVec+xknWXFj4 Y3ayPEBOo9rWtkhvkJJFf5ITJhGEpH1TifAHO/2hd+ZBuKFxMrdn4+fiMNsaG69ZGOWg+MtpYtt 8RqWeF4GlHVNHX9HdwGnMARaQ+tLlVEZqYJ7PbWHR6goCW3kWRN04JFqHfS6IpYICcgobCLG/8u /I4TxTI/9lihyMoIKyzEUDpj3bgqiRUSGaUql+fSOOXkg/qhlaG+Pg0kyIFNfQJkrcJmiXwqRFD htkqKOLooJNZsmwML1feOpdKtm+/OIhXjttlvPkFrAWod+xgJ8b48Dt5kV5JrAe0F8+1tLuHysB AfUQXpOWEdkM9YX/kWkKSFPVrOjKC+a4pNxO3ZAM7R+BAriDH0 X-Received: by 2002:a05:690c:c504:b0:7b4:6f40:635 with SMTP id 00721157ae682-7bdf5da8d8amr143542617b3.16.1778256175066; Fri, 08 May 2026 09:02:55 -0700 (PDT) Received: from localhost ([208.185.137.148]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7bd66838851sm107944737b3.23.2026.05.08.09.02.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 09:02:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 08 May 2026 11:02:53 -0500 Message-Id: Cc: , , , , , Subject: Re: [PATCH v2] iio: chemical: scd30: reject (response=NULL, size>0) in scd30_i2c_command() From: "Maxwell Doose" To: "Stepan Ionichev" , X-Mailer: aerc 0.21.0 References: <20260506181533.409-1-sozdayvek@gmail.com> <20260507152800.9062-1-sozdayvek@gmail.com> In-Reply-To: <20260507152800.9062-1-sozdayvek@gmail.com> On Thu May 7, 2026 at 10:28 AM CDT, Stepan Ionichev wrote: > scd30_i2c_command() takes an opaque "response" buffer plus its size. > At the start of the function the code already checks if response is > NULL (via the rsp local), but the response-decoding loop after the > i2c transfer always dereferences rsp without re-checking. With the > current callers in scd30_core.c this is harmless, since write > commands pass response=3DNULL together with size=3D0 (so the loop body > is never entered). > [snip] > @@ -71,6 +71,9 @@ static int scd30_i2c_command(struct scd30_state *state,= enum scd30_cmd cmd, u16 > int i, ret; > char crc; > > + if (!response && size !=3D 0) > + return -EINVAL; > + > put_unaligned_be16(scd30_i2c_cmd_lookup_tbl[cmd], buf); > i =3D 2; > I guess we're still handling the cases where both response/rsp and size are zero here below? if (rsp) { /* each two bytes are followed by a crc8 */ size +=3D size / 2; } else { put_unaligned_be16(arg, buf + i); crc =3D crc8(scd30_i2c_crc8_tbl, buf + i, 2, CRC8_INIT_VALUE); i +=3D 2; buf[i] =3D crc; i +=3D 1; /* commands below don't take an argument */ if ((cmd =3D=3D CMD_STOP_MEAS) || (cmd =3D=3D CMD_RESET)) i -=3D 3; } Should add a comment showing that this handles this case but that's just my personal nit. Not worth forcing a v3 so Acked-by: Maxwell Doose best regards, max