From patchwork Mon Mar 5 15:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 881545 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::237; helo=mail-wr0-x237.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbxwd6xkakgqe5o4hpmy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=siemens.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="RnsfwuD9"; dkim-atps=neutral Received: from mail-wr0-x237.google.com (mail-wr0-x237.google.com [IPv6:2a00:1450:400c:c0c::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zw3gQ0PFbz9sZT for ; Tue, 6 Mar 2018 02:27:28 +1100 (AEDT) Received: by mail-wr0-x237.google.com with SMTP id d12sf10755763wri.4 for ; Mon, 05 Mar 2018 07:27:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1520263646; cv=pass; d=google.com; s=arc-20160816; b=WNETcvBoTesYxwmAQ/mqnIczp8y17WglSGe9lwJvV3YadxIdFAeOIvf2znqY0P9K9B z4XWNMeKJXBfP13ejVY2cpbh3y3p+HT2XtPX3IzWg2qpUi28fQBDuFJC3uGtffwQ+u/R NLhH7aDnGs0WySg1hHYnQPk+JvGnW+4oV4r/OZR+shOJIxPxA04o+BcR6tkYyla86E8Y Z4Hvu+ape622y00Fg5RYfZWiu4fZjAKKdrnbAtIFNQjxGV8xKq4suOuV8hEmri9DuU84 gA3KM44xAoR7ud99zaAtZs8qAk9BK3jdDaGbbW9bl4WLlQ6gpC6HJ86OXjpin7XpE2ut AU2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=okoVbQ49KE4veHHcI7YQDfUwsR7D6msbGNd4HqLRsFU=; b=wm6QO6g006GhL8aXk2jCmDdspP+tPM1ES8MdbZKVjzEo9tYNGSwGmsTOmmwz+6K2YC 5cTTDxtPBy2FnR3ywNj5T75m+gTGL5c7H4IzR804tbAjN6mXF9flZkWi80nSgYFQY08v gCYe+VKw7KjgdWb5IoQ+UShRFOSZM5xZHzmYC05D/KsPfy5wDy+T7qA7Gy5djR5N1fqY jzhLq41apHVNSAkvEPr8DsiyoZUTmdvDq/DJ0HOrahiHRB6R2HtxidtBc1EZ+AuXJJ3s Q+BM9gQuwmM6Jg29WPq9yLPyivim/bJ8stFkMDIjZq56UE0zwwOf1tRCs/j5IJgLi7BS A1Pw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=okoVbQ49KE4veHHcI7YQDfUwsR7D6msbGNd4HqLRsFU=; b=RnsfwuD9EtjfeoyEw7PqFe/6tQJlhUvJ5url71tUn+H7pV1LNMXqPnDmIJccaXOTaP BfpkaChO9bSVp3g0LSaWeTVdOHBubtQQ7eRLTahOzQ6urRU/o4xqchG3vVqnVEcS4C11 lP1l9fM0RCCOvn/bVojz3HMypLak6UzWODtJ+/x87kHiZfSEeAKWYpYcSZtYAr/ciYQy m9K4++DqC/4anrU8yto2tXyJOixGugoj2lQykUChaz1wbdWvngHA2V7JDHvwDKG1lpIr IGMz1jL/KLGmF8CgYzObp4fv1WoMmSiFuiAWFDvZ42IjYra3HI7aNickEH3EuMpLJ2H8 Up7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=okoVbQ49KE4veHHcI7YQDfUwsR7D6msbGNd4HqLRsFU=; b=Fzgie72jKVbsvfoYEbRLx8gtyd3SAV7USEQ9AvTVUTcACwGTtUvMvWxg5Mn6UHG0SK PO4eXSbmKLaj7IdqpBy8zANjEcdzuXjZ1alJjMx6JrnbEJFqLzasoxvIgSmZLcwRBZe9 7X+vVfto41ozaF/RIpEChbR+V7eQ502pyf5F7JQAP0KwebcimBdzPm+iQ+84clBEE768 trrByOEF8pGIY9IeJG8O1zTqmtu+heN57fGyoyQvungJMuu7jKmNZuMTUFlZv138ssO6 BigLWJ4VSTNLubpETPYo4m52CSLsEmvIJnB85HBNL0N9ljDDM081kFfqP+gPax8unPWh 1DNw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AElRT7F00ks7o67t6OljuruaP/9mzqW8FLNJE1CHzm+Gdu4wOPjlEY2/ YYrh9ySgO02ZIL97GB7ohi0= X-Google-Smtp-Source: AG47ELu6Iu7VtDjN91H8TldVMADgonOhS86tP89MFPZPyaDm5+vRwgAPqwyaq0SCP5JnuBRAs5eEeA== X-Received: by 10.28.122.20 with SMTP id v20mr62525wmc.7.1520263646316; Mon, 05 Mar 2018 07:27:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.213.199 with SMTP id g7ls2864948edj.2.gmail; Mon, 05 Mar 2018 07:27:25 -0800 (PST) X-Received: by 10.80.244.2 with SMTP id r2mr3043951edm.2.1520263645732; Mon, 05 Mar 2018 07:27:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520263645; cv=none; d=google.com; s=arc-20160816; b=uB3qND35HVTkiOmf1eArmImI+lcWTR9JAXkCh7PE/n7c8THXzH1OZrbXXO1Etm84SL c7o0teiG0TAeo7s/eSadwivHhutclQWrmvlSk2hmWSZFnG2zeWGcx38staoEe7/yr6Kt bbPY8Ww9AtlewdAFnpt+avkxxDmopImSm4d1kzHxWg8IWlcLKcm6dooUfyUxc4OpQHeL HXrF80CDtktArAkYZ3YhzN6wpzWFv8DAZMoCXpsUMN/ySOA/vryasIeJlBx1s25S+iTh LRWkhqDWgyCGExIxyvlwlYH9rdDqauiSdgpvtnQUUSLGnpEUjuvyfZpJ/FLu4BRa67XX iRxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=uWG8TCFdg0pwTnNFKL7E1vkOImqKFiRpUg+vLjJhSuM=; b=RSEEGkxlPtvN5OeWT+ft+/kSyECperonCh7rb+mnMDFQ+yD7W0iz5AwslQpz+MuNNE vs27XQOrUWxc8HvgO1I4M5Xb7JNoPDHoBmJPIb22Fsi1vy0bWnjGQ8zGEoC+Ikw2XwW9 Kzo7hO9GBCkeKD9mJRrj91+2W096NvEFlOqrg5GJVy2AbMVqU3AfdS56fchD1nJg5OKm VgLon4zT4UCRPpajGq6woGHqFKmq7l7TEHsBQ78kbDckaZX4NHcg2zrk0f9Ze8Vwpgmt wPMPobXyu679Ud9U7ZgemquJEhTX8c7YIStrqYxD+hY5ANM9eZ1WCH+HypHg56ESS49L zq0g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id f24si623995edc.0.2018.03.05.07.27.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 07:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w25FRPVX029748 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 5 Mar 2018 16:27:25 +0100 Received: from MD1KR9XC.ww002.siemens.net ([139.25.69.202]) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id w25FRPEP030706; Mon, 5 Mar 2018 16:27:25 +0100 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH] Lua: use explicit size for embedded Lua handler script Date: Mon, 5 Mar 2018 16:23:16 +0100 Message-Id: <20180305152316.14928-1-christian.storm@siemens.com> X-Mailer: git-send-email 2.16.2 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The embedded Lua handler script string may not be null- terminated in the .data section, depending on a padding inserted or not. Hence, don't let Lua rely on strlen() when loading the script but calculate the size explicitly. Signed-off-by: Christian Storm Reviewed-by: Stefano Babic --- Makefile.flags | 3 ++- corelib/lua_interface.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile.flags b/Makefile.flags index 207eace..dac790f 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -106,7 +106,8 @@ ifeq ($(CONFIG_HANDLER_IN_LUA),y) ifeq ($(CONFIG_EMBEDDED_LUA_HANDLER),y) ifneq ($(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE),) LDFLAGS_swupdate += -Wl,--format=binary -Wl,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE) -Wl,--format=default -KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_start" +KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC_START="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_start" +KBUILD_CPPFLAGS += -DEMBEDDED_LUA_SRC_END="_binary_$(subst ",,$(subst .,_,$(subst /,_,$(CONFIG_EMBEDDED_LUA_HANDLER_SOURCE))))_end" endif endif endif diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index e96fbe6..3212ea8 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -24,7 +24,8 @@ #define LUA_TYPE_HANDLER 2 #if defined(CONFIG_EMBEDDED_LUA_HANDLER) -extern const char EMBEDDED_LUA_SRC[]; +extern const char EMBEDDED_LUA_SRC_START[]; +extern const char EMBEDDED_LUA_SRC_END[]; #endif #define LUA_PUSH_IMG_STRING(img, attr, field) do { \ @@ -1021,12 +1022,13 @@ int lua_handlers_init(void) lua_pop(gL, 1); /* remove unused copy left on stack */ /* try to load Lua handlers for the swupdate system */ #if defined(CONFIG_EMBEDDED_LUA_HANDLER) - if ((ret = luaL_dostring(gL, EMBEDDED_LUA_SRC)) != 0) { + if ((ret = (luaL_loadbuffer(gL, EMBEDDED_LUA_SRC_START, EMBEDDED_LUA_SRC_END-EMBEDDED_LUA_SRC_START, "LuaHandler") || + lua_pcall(gL, 0, LUA_MULTRET, 0))) != 0) { INFO("No compiled-in Lua handler(s) found."); TRACE("Lua exception:\n%s", lua_tostring(gL, -1)); lua_pop(gL, 1); } else { - INFO("Compiled-in Lua handler(s) found."); + INFO("Compiled-in Lua handler(s) found and loaded."); } #else if ((ret = luaL_dostring(gL, "require (\"swupdate_handlers\")")) != 0) {