{"id":17218,"url":"https://patchwork.libcamera.org/api/1.1/patches/17218/?format=json","web_url":"https://patchwork.libcamera.org/patch/17218/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220829084445.61585-2-tomi.valkeinen@ideasonboard.com>","date":"2022-08-29T08:44:44","name":"[libcamera-devel,v2,1/2] libcamera: base: log: Fix use of freed name","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"38495186bc2f2b66e01c19e99a3c97ea55d5e840","submitter":{"id":109,"url":"https://patchwork.libcamera.org/api/1.1/people/109/?format=json","name":"Tomi Valkeinen","email":"tomi.valkeinen@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17218/mbox/","series":[{"id":3442,"url":"https://patchwork.libcamera.org/api/1.1/series/3442/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3442","date":"2022-08-29T08:44:43","name":"LogCategory fixing","version":2,"mbox":"https://patchwork.libcamera.org/series/3442/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17218/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17218/checks/","tags":{},"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 0D3D0C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Aug 2022 08:45:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B4C561FC6;\n\tMon, 29 Aug 2022 10:45:00 +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 9240761FBF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Aug 2022 10:44:57 +0200 (CEST)","from deskari.lan (91-158-154-79.elisa-laajakaista.fi\n\t[91.158.154.79])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EBD8A8BD;\n\tMon, 29 Aug 2022 10:44:56 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1661762701;\n\tbh=JOn2Yz0SLXrrVjZ/Ulr08TOR1wHDzS96CPzzwSCVj4g=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=hlAm95Ub+nnwsCeaqhhtprTfPj6Qrn6pMEcXuX8G+UgIai9OxbHEMj32RV0CSe3ZY\n\tVjeABGk9xZg5OHlec8QG7VQnPyW22YXbluW+ysblETEq5FOKY/NcpGgvAml/5bC6h1\n\tcwiTGlCi9BmJ53JR1Zbm4tpP3Ji0VR0etRquTYkiKKUkcS4s2HCiGa+pxPb50+9myN\n\tfOOxYaCn2qeersx3s7O9TOoPX96V2w+g8eXoHuJ2AALRN/t3LdiTce4zu21OS3+sNx\n\t80IJpJH89ET8NOi5E4eomOBKM9SKgNpMSqZ/urh8gYrDAwXblRaH6b+gmJnQHpn9/f\n\t2MFP4B1sTEDTQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1661762697;\n\tbh=JOn2Yz0SLXrrVjZ/Ulr08TOR1wHDzS96CPzzwSCVj4g=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=jwXIZjv5WQ3tATotsDuINWt02IKRq0NHBq6w/devM38N8R4z+U+6K+JhZmx1bTXet\n\tvONwDFqP++2c0dfGAU1pNrj/ftZGstdNFdjsBf21MPcuBSUDQ2TB10H4IZrX5jTS39\n\todysSQUkBBE/4v2vlhXHda7OXnkRd1qq+vVmRqos="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"jwXIZjv5\"; dkim-atps=neutral","To":"libcamera-devel <libcamera-devel@lists.libcamera.org>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Mon, 29 Aug 2022 11:44:44 +0300","Message-Id":"<20220829084445.61585-2-tomi.valkeinen@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20220829084445.61585-1-tomi.valkeinen@ideasonboard.com>","References":"<20220829084445.61585-1-tomi.valkeinen@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"LogCategory just stores the char * that was given to it in the\nconstructor, i.e. it refers to memory \"outside\" LogCategory. If the\nLogCategory is defined in a .so that is unloaded, then it leads to the\nLogCategory pointing to freed memory, causing a crash.\n\nFix this by taking a copy of the name by using a std::string instead of\njust storing the pointer.\n\nSigned-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/base/log.h | 4 ++--\n src/libcamera/base/log.cpp   | 2 +-\n 2 files changed, 3 insertions(+), 3 deletions(-)","diff":"diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h\nindex 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 \ndiff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\nindex 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}\n","prefixes":["libcamera-devel","v2","1/2"]}