From patchwork Mon Jun 10 21:00:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 1388 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA12B61918 for ; Mon, 10 Jun 2019 23:00:30 +0200 (CEST) X-Halon-ID: c47df497-8bc2-11e9-8d05-005056917f90 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA id c47df497-8bc2-11e9-8d05-005056917f90; Mon, 10 Jun 2019 23:00:29 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Mon, 10 Jun 2019 23:00:23 +0200 Message-Id: <20190610210023.4185-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2] libcamera: ipa_manager: Fix handling of unset LIBCAMERA_IPA_MODULE_PATH X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jun 2019 21:00:31 -0000 If the environment variable LIBCAMERA_IPA_MODULE_PATH is not set utils::secure_getenv() will return a nullptr. Assigning a nullptr to a std::string is not valid and results in a crash, terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid Fix this by operating directly on the returned char array instead of turning it into a std::string. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/ipa_manager.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libcamera/ipa_manager.cpp b/src/libcamera/ipa_manager.cpp index f689aa69b7284092..b9b772d1d5e7795f 100644 --- a/src/libcamera/ipa_manager.cpp +++ b/src/libcamera/ipa_manager.cpp @@ -34,19 +34,22 @@ IPAManager::IPAManager() { addDir(IPA_MODULE_DIR); - std::string modulePaths = utils::secure_getenv("LIBCAMERA_IPA_MODULE_PATH"); - if (modulePaths.empty()) + const char *modulePaths = utils::secure_getenv("LIBCAMERA_IPA_MODULE_PATH"); + if (!modulePaths) return; - for (size_t pos = 0, delim = 0; delim != std::string::npos; - pos = delim + 1) { - delim = modulePaths.find(':', pos); - size_t count = delim == std::string::npos ? delim : delim - pos; - std::string path = modulePaths.substr(pos, count); - if (path.empty()) - continue; + while (1) { + const char *delim = strchrnul(modulePaths, ':'); + size_t count = delim - modulePaths; - addDir(path.c_str()); + std::string path(modulePaths, count); + if (!path.empty()) + addDir(path.c_str()); + + if (*delim == '\0') + break; + + modulePaths += count + 1; } }