[{"id":20035,"web_url":"https://patchwork.libcamera.org/comment/20035/","msgid":"<YVtxh8q5MiK5TVjq@pendragon.ideasonboard.com>","date":"2021-10-04T21:26:31","subject":"Re: [libcamera-devel] [PATCH v2 1/2] gstreamer: Check if Stream\n\tconfigurations were generated correctly","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Javier,\n\nThank you for the patch.\n\nOn Fri, Oct 01, 2021 at 11:15:24PM +0200, Javier Martinez Canillas wrote:\n> Currently, the gst_libcamera_device_new() function assumes that a call to\n> Camera::generateConfiguration() will always succeed, but that may not be\n> the case and the return value must to be checked.\n> \n> Otherwise, this could lead to a NULL pointer dereference if the pipeline\n> handler fails to generate a config for the VideoRecording stream role.\n> \n> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>\n> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI'll push this patch independently of 2/2 as there's an open question\nthere.\n\n> ---\n> \n> Changes in v2:\n> - Fix typos in commit message as pointed out by Nicolas Dufresne.\n> - Add Nicolas Dufresne's Reviewed-by tag.\n> \n>  src/gstreamer/gstlibcameraprovider.cpp | 14 +++++++++++++-\n>  1 file changed, 13 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp\n> index aee6f9a2be2..6eb0a0eb0c4 100644\n> --- a/src/gstreamer/gstlibcameraprovider.cpp\n> +++ b/src/gstreamer/gstlibcameraprovider.cpp\n> @@ -132,6 +132,10 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)\n>  \n>  \troles.push_back(StreamRole::VideoRecording);\n>  \tstd::unique_ptr<CameraConfiguration> config = camera->generateConfiguration(roles);\n> +\tif (!config || config->size() != roles.size()) {\n> +\t\tGST_ERROR(\"Failed to generate a default configuration for %s\", name);\n> +\t\treturn nullptr;\n> +\t}\n>  \n>  \tfor (const StreamConfiguration &stream_cfg : *config) {\n>  \t\tGstCaps *sub_caps = gst_libcamera_stream_formats_to_caps(stream_cfg.formats());\n> @@ -189,8 +193,16 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)\n>  \n>  \tfor (const std::shared_ptr<Camera> &camera : cm->cameras()) {\n>  \t\tGST_INFO_OBJECT(self, \"Found camera '%s'\", camera->id().c_str());\n> +\n> +\t\tGstDevice *dev = gst_libcamera_device_new(camera);\n> +\t\tif (!dev) {\n> +\t\t\tGST_ERROR_OBJECT(self, \"Failed to add camera '%s'\",\n> +\t\t\t\t\t camera->id().c_str());\n> +\t\t\treturn nullptr;\n> +\t\t}\n> +\n>  \t\tdevices = g_list_append(devices,\n> -\t\t\t\t\tg_object_ref_sink(gst_libcamera_device_new(camera)));\n> +\t\t\t\t\tg_object_ref_sink(dev));\n>  \t}\n>  \n>  \treturn devices;","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 080F2C3243\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Oct 2021 21:26:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6ADBA691B6;\n\tMon,  4 Oct 2021 23:26:40 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0D4BD6023F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  4 Oct 2021 23:26:39 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 622875A1;\n\tMon,  4 Oct 2021 23:26:38 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Mxb0NE9t\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1633382798;\n\tbh=SilsjwMdN8s+EgORguoeBwu5aE96r+CEPSc6ZjBF418=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Mxb0NE9t1lzC4Sguk1MhCclEEn16JxfgMWcEhfS0m1N9Shm2h/AneU/JGXNLzAhsu\n\thiNHFsNfXWp+QFv419YRx4H/6ABB3orTlciF18w3dbc0R+9FLT1qDCDnMu0+wnatnP\n\txmS+qc61w5b4+M5Ratn8/brBouxbmBB6krI+22mI=","Date":"Tue, 5 Oct 2021 00:26:31 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Javier Martinez Canillas <javierm@redhat.com>","Message-ID":"<YVtxh8q5MiK5TVjq@pendragon.ideasonboard.com>","References":"<20211001211525.1423725-1-javierm@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20211001211525.1423725-1-javierm@redhat.com>","Subject":"Re: [libcamera-devel] [PATCH v2 1/2] gstreamer: Check if Stream\n\tconfigurations were generated correctly","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]