From patchwork Tue Jun 1 20:56:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 12482 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 7B913C3206 for ; Tue, 1 Jun 2021 20:57:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E3CE968920; Tue, 1 Jun 2021 22:57:20 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="p7aJTZV9"; dkim-atps=neutral Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 46B5B6891F for ; Tue, 1 Jun 2021 22:57:19 +0200 (CEST) Received: by mail-pf1-x42c.google.com with SMTP id x73so459022pfc.8 for ; Tue, 01 Jun 2021 13:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AxoMVPvoCK9eJz8qPA2++Hzla1H7A3U/vm22XPKhKj0=; b=p7aJTZV9zEUWMFmCfrgJNd0JmkNbhnC6CkF4hFf7HROMc00dy1D09uIPR6nOG+fGqU 6fcb5CSy9IWt0bS/NDVS88Yg/+fRioSXoWBsov1g6tLfqoG4uoRltIdaGxMfPeSfy2M7 8zWeQ85b/HOHAkGAYVO8u01svw7xSE4ymVtrU2nqKXSpc+aa8G0EmEQhHGW0QPc2rRxC eRHZe1b1UcbJ+SdK7Lo3f5cB4bqzGU7KGQPEnxKbrXDieEsYCkl9KTJrLy134FsHP2vB nBv2FY3F4uYasmjxF/oIB5PuVAQECd4GlU5RFnaTO+qwiGpmsnvJkQ8CdAanbAFGeb3B qhQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AxoMVPvoCK9eJz8qPA2++Hzla1H7A3U/vm22XPKhKj0=; b=J1XVNQ9EOo+VzJ/s5URd2emjtqpjmwhdsPooZRuA9d5H/8QovOsORLqSEWLUEcPCJB +IVOZorFiq7nylDp1zdk7NGGdExM7Fs7BsxoRGq8/KtQ57UrMRqvTzCyH7F5ACp6pLD8 fAhNRBxHzGfHN0bQ+tafXcuL0cO6ICBJm7U1lkeNnmxGOBci976oi3XH37BVlBGJkWfH mPn3Kmk+iWXGcYTSgVi/2AvjJPmZ67m1/APmWIAU4olY+H4h2/Ma86euEQ3sYzr6YsJA ICY+GCPp2EBYSzyeTAr9YfMVLHCttsidF6+udh3nHET2xTVpLaGz/AUQFwY3IcmOfPZx /Y4w== X-Gm-Message-State: AOAM531LY+UU4Oc79U7KOmacjFkoGJlJS+0ltQ6uH6MaLvZD8D45WdyA xWiIitcOb73uFOYTfqVkNfleZRBUgGD8iQ== X-Google-Smtp-Source: ABdhPJxgtBS/WFwEvXoTpplr0RUMqKcMEowyOdXPXQknLvYA/8T46AWXEhZNA8r2Js6I0Ho7XA61Hg== X-Received: by 2002:a05:6a00:1a8c:b029:2e9:a532:148a with SMTP id e12-20020a056a001a8cb02902e9a532148amr18421719pfv.38.1622581037329; Tue, 01 Jun 2021 13:57:17 -0700 (PDT) Received: from localhost.localdomain ([1.186.76.76]) by smtp.googlemail.com with ESMTPSA id h18sm10394038pgl.87.2021.06.01.13.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 13:57:16 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Jun 2021 02:26:40 +0530 Message-Id: <20210601205640.14334-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3] gstreamer: Add error checking in gst_libcamera_src_task_enter() 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: , Cc: Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Error checking the output from generateConfiguration() was missing in the code. Only assert was added as a guard which checked if the size of generated camera config was equal to size of roles passed to it. If the roles argument has a invalid member, it will return a nullptr and then trying to access a member on a nullptr for size comparison will result in a segmentation fault. So, if the function returns a nullptr, it will simply push an error message on GstBus and gracefully exit. Signed-off-by: Vedant Paranjape Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamerasrc.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 87246b40..ccc61590 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -375,10 +375,13 @@ gst_libcamera_src_task_enter(GstTask *task, [[maybe_unused]] GThread *thread, /* Generate the stream configurations, there should be one per pad. */ state->config_ = state->cam_->generateConfiguration(roles); - /* - * \todo Check if camera may increase or decrease the number of streams - * regardless of the number of roles. - */ + if (state->config_ == nullptr) { + GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, + ("Failed to generate camera configuration from roles"), + ("Camera::generateConfiguration() returned nullptr")); + gst_task_stop(task); + return; + } g_assert(state->config_->size() == state->srcpads_.size()); for (gsize i = 0; i < state->srcpads_.size(); i++) {