From patchwork Wed Jun 2 14:11:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 12488 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 6D7F2C3206 for ; Wed, 2 Jun 2021 14:12:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B737D6050E; Wed, 2 Jun 2021 16:12:11 +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="EtVP0m5G"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DA87B602A4 for ; Wed, 2 Jun 2021 16:12:10 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id t28so2265989pfg.10 for ; Wed, 02 Jun 2021 07:12:10 -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=SbK0I8xpvPDcvtfHcRdhUVxXQi27eU32jcL2FhTducs=; b=EtVP0m5Ghl0HGOFXGxJWjapO/wndchTc6tINvtcImN/+WUmR5D1rcvKRdGEFcDlrPd 1/klyWbJO77YXK46WLjTSW/tOJqYRvnJs/2jPXZSNLDUkr29gpKoP7dK585FS+zdOlc5 6hEc4v0jS/3PqREoJD+vEy1rMYZ7N9N+l2NJSm7Eu0lVg+AlFQsTIgDQxywIEWpXiYU0 xlIn7sbHhpNkCHyDjlC1ulk5CcJ7yD6yWmyylhJonXVgppfV2wve8LUWAKrsVXYpJ1C/ gIimF3adBUwQs05Mre7nIdXXORjDcPdPpVg3KlJTM5woR4c0DNFyIVRucJBxmYNlkxtN 5Ffw== 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=SbK0I8xpvPDcvtfHcRdhUVxXQi27eU32jcL2FhTducs=; b=qsnlso7IWAMD4q1po2hPQXv+n0cZNBgG6oWqTJw7SWhC/ZWlmT7WeUXaqmMkTFBTBG SfHG3sw1Wuh9xJben+K8Kodi/bbtvKI/AOFIuX/Wt/0wHIcjYHhYq546QrW+jilH3Pgl WyR9oDrjqgGvdTeTMxPkCkJGt7P4z1YfN0DCh14W4ChAMZzoCHxPXP8HHAC1dMBiqoEb A2OKvdQ1UdzlQAaUdbGqdGiyqlTEUsmvLJIR8gAyUhqGQ+xu/peRI3yZZGGg1CaqFLvA nLEkwAev8iUmIHiHqF+KH/DY1uK+NbV+QDWcqAzesrBQamIRh9MhPeOJfPPFzBra31PD GrnQ== X-Gm-Message-State: AOAM5334dX9axiJ8GGhsUtl6LBFW+weowEfSE2ecubTRzUu8L8Fg2VMS 4geHtNwW6+giV0cI42FBfqV93khuHJVyk3JJ X-Google-Smtp-Source: ABdhPJzez3I6T9ou7ZowqSBKoAYBk7B2MqoaFInqvuuNJqp0h2EwmSztAYLS+ydX/pqQ/xw6ER+QNA== X-Received: by 2002:a05:6a00:2b5:b029:2ea:a29:a117 with SMTP id q21-20020a056a0002b5b02902ea0a29a117mr6966628pfs.35.1622643128617; Wed, 02 Jun 2021 07:12:08 -0700 (PDT) Received: from localhost.localdomain ([1.186.77.76]) by smtp.googlemail.com with ESMTPSA id h13sm11124122pfv.213.2021.06.02.07.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 07:12:08 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 2 Jun 2021 19:41:38 +0530 Message-Id: <20210602141138.582472-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4] 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" The return value from generateConfiguration() was not checked. 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 variable has an invalid/unsupported role, 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: Paul Elder 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++) {