[{"id":22535,"web_url":"https://patchwork.libcamera.org/comment/22535/","msgid":"<164874293073.15275.18317004557451612734@Monstersaurus>","date":"2022-03-31T16:08:50","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Fix\n\tpotential errno overwrite","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2022-03-31 16:45:26)\n> The errno variable can potentially be overwritten by operator<<(). Store\n> it in a local variable before logging the error message.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  src/libcamera/v4l2_videodevice.cpp | 9 ++++++---\n>  1 file changed, 6 insertions(+), 3 deletions(-)\n> \n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 009f6d55610f..0830be80c553 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -647,14 +647,17 @@ int V4L2VideoDevice::open()\n>   */\n>  int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)\n>  {\n> +       int ret;\n> +\n>         UniqueFD newFd = handle.dup();\n>         if (!newFd.isValid()) {\n> +               ret = -errno;\n>                 LOG(V4L2, Error) << \"Failed to duplicate file handle: \"\n> -                                << strerror(errno);\n> -               return -errno;\n> +                                << strerror(-ret);\n> +               return ret;\n>         }\n>  \n> -       int ret = V4L2Device::setFd(std::move(newFd));\n> +       ret = V4L2Device::setFd(std::move(newFd));\n>         if (ret < 0) {\n>                 LOG(V4L2, Error) << \"Failed to set file handle: \"\n>                                  << strerror(-ret);\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","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 BA5E5C0F1B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Mar 2022 16:08:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C6C3665633;\n\tThu, 31 Mar 2022 18:08:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C00EB6559A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Mar 2022 18:08:53 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 50D25486;\n\tThu, 31 Mar 2022 18:08:53 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648742934;\n\tbh=kFh6cHEttjTfJP0vSjdjnFZk2NWUptxlk83xaV4+3Yk=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=kxa/2tTXAm5O0sdMtMWRQyvS5YVk7g2ZIQ0CdOINvDrnn9RuhpDkRlP3+XFQpUba2\n\t9DC2LLOWa8OC16G6/2RbfbPQuuNBJfcGVtOE3DncQqDEjAYJNP1q1WhngmZ+/p6r9w\n\tGoScqx8SIKUbM2TFzZam9NDUWev1FuG8gLZOdfxR2APd3W7Hweyr8FvewGL0SbFffC\n\tr5eGq0yvYuVyk7cTfLZobwYdQj5gCdQJ0jSvhAZPcB9mZZGloft/1HLKCWV7jEkKKR\n\tSEZxNwk+0VrNY11qzVCxKTvqf2JvqrpTvF6Heo9vbPu46ICQPk2VOXsITXQrU2Px8E\n\tYKq8oxJOkI1NA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648742933;\n\tbh=kFh6cHEttjTfJP0vSjdjnFZk2NWUptxlk83xaV4+3Yk=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=OPLfMNHAyodOF96QTr/yhmEe6IOJNU1XcsyNVdKvGeXevWqSQcTTmL4v4kcCbz/sd\n\toghCF3EV8uhW9dGdo2nclfJpWk0+Js19to51oE+sX2ipaNRUlGVR/ZBGUf8ONAHi+r\n\tYukYVV5vgrb3qnjLF/nO3aGpO5yP2hrLOMUeY02w="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OPLfMNHA\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20220331154526.27882-1-laurent.pinchart@ideasonboard.com>","References":"<20220331154526.27882-1-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 31 Mar 2022 17:08:50 +0100","Message-ID":"<164874293073.15275.18317004557451612734@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Fix\n\tpotential errno overwrite","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>","From":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":22536,"web_url":"https://patchwork.libcamera.org/comment/22536/","msgid":"<cacc5888-ff65-9242-55fc-6763376bce3a@ideasonboard.com>","date":"2022-03-31T16:28:50","subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Fix\n\tpotential errno overwrite","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hello,\n\nOn 3/31/22 21:15, Laurent Pinchart via libcamera-devel wrote:\n> The errno variable can potentially be overwritten by operator<<(). Store\n\n\nAh good to know!\n\n> it in a local variable before logging the error message.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\n\n> ---\n>   src/libcamera/v4l2_videodevice.cpp | 9 ++++++---\n>   1 file changed, 6 insertions(+), 3 deletions(-)\n>\n> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp\n> index 009f6d55610f..0830be80c553 100644\n> --- a/src/libcamera/v4l2_videodevice.cpp\n> +++ b/src/libcamera/v4l2_videodevice.cpp\n> @@ -647,14 +647,17 @@ int V4L2VideoDevice::open()\n>    */\n>   int V4L2VideoDevice::open(SharedFD handle, enum v4l2_buf_type type)\n>   {\n> +\tint ret;\n> +\n>   \tUniqueFD newFd = handle.dup();\n>   \tif (!newFd.isValid()) {\n> +\t\tret = -errno;\n>   \t\tLOG(V4L2, Error) << \"Failed to duplicate file handle: \"\n> -\t\t\t\t << strerror(errno);\n> -\t\treturn -errno;\n> +\t\t\t\t << strerror(-ret);\n> +\t\treturn ret;\n>   \t}\n>   \n> -\tint ret = V4L2Device::setFd(std::move(newFd));\n> +\tret = V4L2Device::setFd(std::move(newFd));\n>   \tif (ret < 0) {\n>   \t\tLOG(V4L2, Error) << \"Failed to set file handle: \"\n>   \t\t\t\t << strerror(-ret);","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 99ECBC3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 31 Mar 2022 16:29:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E89C465631;\n\tThu, 31 Mar 2022 18:29:17 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 693116559A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 31 Mar 2022 18:29:16 +0200 (CEST)","from [192.168.1.105] (unknown [103.74.73.150])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D7A00486;\n\tThu, 31 Mar 2022 18:29:07 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1648744157;\n\tbh=m+emsmkywrH3ZPwp9WBluauwur7lLB68fVgMH8rMe3E=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=WoToneigpct8MEaoQI7XlEmacekgJDLI6BeOacWrMau0d4NeoZmGcDmwU0Nm+cGv2\n\tP7d2jegnx+MB9V5fJwfLaZuMAsQO7y+dBm1mTdkF4CUn114nbxRB0wkRZUqkTb38w1\n\tTg6Qc5+g96v8CyIkxUpEex+yO8hw3OBRZPdj+LygSThPQjBxzMOq6yFhE56Gghg/RA\n\tGyn/AXCv1TMK13Lo33wtcW7hyv6oSKIf3ucKe74A7IIZ+QARFjLiu+7Ok8EekXxK4o\n\t+UbPftGZlh/HVKbfAoF95/WXlvQ5/yPE6v3ss6ZncJpt4JWFHN6B7iH00IXtHx/JSk\n\tWFt+lXo3DKMdA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1648744156;\n\tbh=m+emsmkywrH3ZPwp9WBluauwur7lLB68fVgMH8rMe3E=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=pjV4v4dJndCZuf+Vy6VQxQWELIWnlO6vg74p6INaOHwMRCKx1v+Z79me8LxvrcDc+\n\tTaAviOQwnX4EQ91Q0nOnNU4aHYyeQTZWb6Qs/MMqrInV9uA/NlkRnKcAiapPy+xJMU\n\tzvaboFDMFDODJePOgeIl3E/vepB4Yn5Z231rfKSs="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"pjV4v4dJ\"; dkim-atps=neutral","Message-ID":"<cacc5888-ff65-9242-55fc-6763376bce3a@ideasonboard.com>","Date":"Thu, 31 Mar 2022 21:58:50 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.4.1","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20220331154526.27882-1-laurent.pinchart@ideasonboard.com>","In-Reply-To":"<20220331154526.27882-1-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH] libcamera: v4l2_videodevice: Fix\n\tpotential errno overwrite","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>","From":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]