[{"id":24802,"web_url":"https://patchwork.libcamera.org/comment/24802/","msgid":"<YwlzTAW/klz1F19w@pendragon.ideasonboard.com>","date":"2022-08-27T01:28:44","subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: base: log: Fix use of\n\tfreed name","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Tomi,\n\nThank you for the patch.\n\nOn Fri, Aug 26, 2022 at 02:39:30PM +0300, Tomi Valkeinen via libcamera-devel wrote:\n> LogCategory just stores the char * that was given to it in the\n> constructor, i.e. it refers to memory \"outside\" LogCategory. If the\n> LogCategory is defined in a .so that is unloaded, then it leads to the\n> LogCategory pointing to freed memory, causing a crash.\n> \n> Fix this by taking a copy of the name by using a std::string instead of\n> just storing the pointer.\n> \n> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nI won't apply this yet though, as it doesn't help much without 2/2, in\ncase this patch needs to change in v2 due to changes in 2/2.\n\n> ---\n>  include/libcamera/base/log.h | 4 ++--\n>  src/libcamera/base/log.cpp   | 2 +-\n>  2 files changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h\n> index 3fc5ced3..8b462767 100644\n> --- a/include/libcamera/base/log.h\n> +++ b/include/libcamera/base/log.h\n> @@ -31,14 +31,14 @@ class LogCategory\n>  public:\n>  \texplicit LogCategory(const char *name);\n>  \n> -\tconst char *name() const { return name_; }\n> +\tconst std::string &name() const { return name_; }\n>  \tLogSeverity severity() const { return severity_; }\n>  \tvoid setSeverity(LogSeverity severity);\n>  \n>  \tstatic const LogCategory &defaultCategory();\n>  \n>  private:\n> -\tconst char *name_;\n> +\tconst std::string name_;\n>  \tLogSeverity severity_;\n>  };\n>  \n> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\n> index 5c359a22..a4a5b452 100644\n> --- a/src/libcamera/base/log.cpp\n> +++ b/src/libcamera/base/log.cpp\n> @@ -568,7 +568,7 @@ void Logger::logSetLevel(const char *category, const char *level)\n>  \t\treturn;\n>  \n>  \tfor (LogCategory *c : categories_) {\n> -\t\tif (!strcmp(c->name(), category)) {\n> +\t\tif (c->name() == category) {\n>  \t\t\tc->setSeverity(severity);\n>  \t\t\tbreak;\n>  \t\t}","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 5F136C3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 27 Aug 2022 01:28:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2397E61FBB;\n\tSat, 27 Aug 2022 03:28:54 +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 6F2C4603E1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 27 Aug 2022 03:28:52 +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 F13684A8;\n\tSat, 27 Aug 2022 03:28:51 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661563734;\n\tbh=Wok5na55yMxKyvNgh4gpND/pWc+KdjrR7Ekb/fKKwQM=;\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:Cc:\n\tFrom;\n\tb=UKMsOGPcJrbPCAoqnQnSva/phnKoxDKQwqiBe59cksIHMSGyMGOhiSAi6pPFEZi5K\n\tonjkKL0vR9i1HtJ5lHcx+jPqaReowPiW8T/fcOqaL5bWGjMGvNZ2wkdKWnNKeAOPi2\n\tTf6X9NMqmv+0RXGQxjJQrp5/+dC57ValXhyFdR32NUnxeIVnigC4XvevEs+l0vHUNb\n\t2br0A4Lr11Od9ViTxImRw6eID1yfTzuImEnZB/Tv5BHp7Y+b599f5SgnK51rDBI82s\n\tQURHydUCZqjl2Tv7sXjJqK5+GEXUN9SNm1J+aDIglvGK+Saj5PN9kjw8qUBFAFYZa2\n\tRjhF3EUJ0AWOQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661563732;\n\tbh=Wok5na55yMxKyvNgh4gpND/pWc+KdjrR7Ekb/fKKwQM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Nq+6DRi8oq4vl/jc1yJsFEcBMkKcfRjGhAU+FrnOStObm2B44QyZajEdid4SUqc9w\n\tTvOhz/0Uh0oUQ8Z1Yt/dFxZhvgafPYgWCmfqmPBjAkQwpFKk+05HyjXEz1NQMBX/Uh\n\t/rfrAPveXFAcNh7efgLuOfz5M94pgXHkPtliS/6w="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"Nq+6DRi8\"; dkim-atps=neutral","Date":"Sat, 27 Aug 2022 04:28:44 +0300","To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Message-ID":"<YwlzTAW/klz1F19w@pendragon.ideasonboard.com>","References":"<20220826113931.59323-1-tomi.valkeinen@ideasonboard.com>\n\t<20220826113931.59323-2-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220826113931.59323-2-tomi.valkeinen@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: base: log: Fix use of\n\tfreed name","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":24803,"web_url":"https://patchwork.libcamera.org/comment/24803/","msgid":"<700a44e7-b6b7-1bbc-e563-b32385d9c695@ideasonboard.com>","date":"2022-08-27T07:23:14","subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: base: log: Fix use of\n\tfreed name","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/people/109/","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"content":"On 27/08/2022 04:28, Laurent Pinchart wrote:\n> Hi Tomi,\n> \n> Thank you for the patch.\n> \n> On Fri, Aug 26, 2022 at 02:39:30PM +0300, Tomi Valkeinen via libcamera-devel wrote:\n>> LogCategory just stores the char * that was given to it in the\n>> constructor, i.e. it refers to memory \"outside\" LogCategory. If the\n>> LogCategory is defined in a .so that is unloaded, then it leads to the\n>> LogCategory pointing to freed memory, causing a crash.\n>>\n>> Fix this by taking a copy of the name by using a std::string instead of\n>> just storing the pointer.\n>>\n>> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> I won't apply this yet though, as it doesn't help much without 2/2, in\n> case this patch needs to change in v2 due to changes in 2/2.\n\nThis does help alone, as it fixes a crash. The issues the second patch \nfixes are not fatal.\n\nBut no hurry to apply this, I think, as \"no one\" constructs \nCameraManagers multiple times... So lets get the second patch ready \nbefore applying this.\n\n  Tomi","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 0A39DC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 27 Aug 2022 07:23:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4D8D561FC0;\n\tSat, 27 Aug 2022 09:23:19 +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 75BA461FBC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 27 Aug 2022 09:23:18 +0200 (CEST)","from [192.168.1.111] (91-158-154-79.elisa-laajakaista.fi\n\t[91.158.154.79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CCCE34A8;\n\tSat, 27 Aug 2022 09:23:17 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661584999;\n\tbh=fRXI4VOyRBbeNwnVeVR8/l3hSxzW22HdYirK5QsJrCw=;\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:Cc:\n\tFrom;\n\tb=xVJUW/AFCfWNA53aRPoSrbMUlTn29NLilPCVlZdFYpjORS5UAZKD/DDIx49VyWL/2\n\tKfobDU9NxEMC3wDo6n9W61c32vmxqD0r/xtbCHxzZbXEjRm5RjmCDEHl1mDajFrzvk\n\t3Frct1FalpTJtxNmLbpNtcOh2a6ekZLsKxeYLeMr+zo/xs5aRFz3/CCQ6r6fIDwF+U\n\tgABQ7ngPT3AAsF3ZiRwdBWWRWiXpchZAyjFTjRx+2twq1zKzz6ch4BDYILLwkHiVpb\n\tfT+nkqkZP2g0IQbNB7hZYU8TbrrVi0XGO9V+qqwW3ljMgFjHtuyu6Z0AuUwU6cZyff\n\tZ6A3X2/4iG1mg==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661584997;\n\tbh=fRXI4VOyRBbeNwnVeVR8/l3hSxzW22HdYirK5QsJrCw=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=qq8NEP4WKPgmC+HuZf397Nqqu2aQURVYICOilPOFLbPg/HAX25YRfLHwWt5HcQBZW\n\taFd2xNh+ahLzuzpFNMe5GrysiXKRLAx0KrGtpQ4u3hWECuppA5AGeQzbffioMWIrm4\n\t4bSvQSz0mH49+xc3sPqJXq2xolHHT1EyeNYymRts="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qq8NEP4W\"; dkim-atps=neutral","Message-ID":"<700a44e7-b6b7-1bbc-e563-b32385d9c695@ideasonboard.com>","Date":"Sat, 27 Aug 2022 10:23:14 +0300","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101\n\tThunderbird/91.11.0","Content-Language":"en-US","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20220826113931.59323-1-tomi.valkeinen@ideasonboard.com>\n\t<20220826113931.59323-2-tomi.valkeinen@ideasonboard.com>\n\t<YwlzTAW/klz1F19w@pendragon.ideasonboard.com>","In-Reply-To":"<YwlzTAW/klz1F19w@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH 1/2] libcamera: base: log: Fix use of\n\tfreed name","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":"Tomi Valkeinen via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Cc":"libcamera-devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]