From patchwork Thu Sep 14 09:27:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 19004 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8D326BD160 for ; Thu, 14 Sep 2023 09:28:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8DDA162900; Thu, 14 Sep 2023 11:28:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1694683719; bh=BQ3orsXtjyytLL4kkTSY6sqs8qQDJT3TAWNcm9HyoxI=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=P9ofEE9uPh6nEFcEw9QNlx4u+EGy0ptW1SwbY9lD8/eUpGgIKBbybBAqKdyEgB/Xs 7a5tF+ACJjsE1AimN1lkutJ5JnEQ/+VtaVj2+1TKa9H6w9ODkNLB/dg/dF4oRkcu/V Hpd/2owpFiSoiG/dJhvwA3fjdfd4fKEDrob5H640rDi9m60DsaMvPfMDMvGFNiRMvm JObJEmBD6bMJEyV+apEr5oyOYI/MhqO39pwgM5grkD5HbwNfoDIufsWnJBWOYo9IIC d2oer7NiXQ7sKayaySZ6ZfcdGyfAEU5JR8T0kjxp0RfpSuzVbCNZNrLySW6+iSvw2K O+M5KxZqDmHLw== Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 954FE628E9 for ; Thu, 14 Sep 2023 11:28:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Jr9clZYb"; dkim-atps=neutral Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2bd0d135ca3so11331541fa.3 for ; Thu, 14 Sep 2023 02:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1694683716; x=1695288516; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=G0zu+/96v9V4RFdf5Ray1Vtuuivsb3Sgh2IjVypzuJQ=; b=Jr9clZYbOBmt4M0NSHrGp/TSLJTTLo2nM9SqrlC6Y0m9KcJOqaWzB5r5dNph66QLWC hQXISSkqqZ3Ar5GrsDxV7XyKKFV5x468LpEVScMFyEzI3NUfRJHjWO+bMSuSf0tc1i4i z0Reku1CTbkFCW/oVvXVV0NCp3vzAF+ywHMw0Ni9quyo85Rv2w848Asjg5f5mvi4A4ca 8iw/uNwyr2cMQcdgCO2mGVgP6CSi+WA1/EmVzqfaT5+mGzqWr4Uixd6vHb1Ckx6BFnNB WB0ijPHM0tCRO/ahfmYfNYWvRgjDZ/IOfYei/jU/1F1woT7587PFiWB+iryJMmVSwoHX kvzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694683716; x=1695288516; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G0zu+/96v9V4RFdf5Ray1Vtuuivsb3Sgh2IjVypzuJQ=; b=kAW6QIRcWdaRnKbFftQ2jb2B4iL+tpxyR+faUdoA2ZeGIPBeE/oBsh76wIzVhCgepu 2MZSXVGo8MDJCjOZpxjs7l3b5G1rsJRVl900KosulvWsncSDg6XGZC1DJ6UaHDHnzMog +6KY4ydWiqddpWYgzbASFgRXtNNVye0oj01NP+dMH6uYL+lc8F85sPJhqm1ID8L7akmD FTOJHGnVWMn1BLNIquFRfl+YG7Xt6TvcKS89/RL5DNY4TJq2xy/dq3rFgGBG8zhd5C5m 8125QvykPneV6qYUqPbkuym/AZssOVxJqALfvbIsekKupn67JlINoMAo72dbKIrJT5b6 OE4A== X-Gm-Message-State: AOJu0YxNrkNfp1sPlLlVwa0Vo6M1zqlf3UzBb3Fcm8GD4A7/BeQJfhFJ pMXfd3blKyq2yHJtrS0fo/nERpuXxU83t9i+PJCKHA== X-Google-Smtp-Source: AGHT+IG/ITvIffqOHBZaC/VhlkuLzNIl2PK7TdC36vr9JMVmN9NyG/8d8fN3gCN1hOME/M+sBs1ZHQ== X-Received: by 2002:a2e:a3d7:0:b0:2b9:c046:8617 with SMTP id w23-20020a2ea3d7000000b002b9c0468617mr3861995lje.5.1694683716318; Thu, 14 Sep 2023 02:28:36 -0700 (PDT) Received: from localhost.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id f20-20020a7bcd14000000b003fe2b6d64c8sm4268849wmj.21.2023.09.14.02.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 02:28:35 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 14 Sep 2023 10:27:56 +0100 Message-Id: <20230914092756.31516-1-naush@raspberrypi.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] ipa: rpi: Fix segfault when parsing invalid json file X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Naushir Patuck via libcamera-devel From: Naushir Patuck Reply-To: Naushir Patuck Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" If the json file parsing failed due to a malformed file, the root pointer would be null. This was not tested and caused a segfault when trying to use the pointer to retrive the version key. Fix this by bailing out early if the parser returns a null pointer. Signed-off-by: Naushir Patuck Reviewed-by: David Plowman Reviewed-by: Jacopo Mondi --- src/ipa/rpi/controller/controller.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ipa/rpi/controller/controller.cpp b/src/ipa/rpi/controller/controller.cpp index fa1721130783..14d245da2ce7 100644 --- a/src/ipa/rpi/controller/controller.cpp +++ b/src/ipa/rpi/controller/controller.cpp @@ -56,6 +56,9 @@ int Controller::read(char const *filename) } std::unique_ptr root = YamlParser::parse(file); + if (!root) + return -EINVAL; + double version = (*root)["version"].get(1.0); target_ = (*root)["target"].get("bcm2835");