From patchwork Tue Aug 31 10:39:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: adrian.frances@netduma.com X-Patchwork-Id: 1522526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=H3o8kW1n; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netduma-com.20150623.gappssmtp.com header.i=@netduma-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=0oNNMGrF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GzNzH2zM4z9sR4 for ; Tue, 31 Aug 2021 20:41:47 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=A7Ibk8cOFStu6MNKa8KR2P6PF7pyUBCoGDyonVf5EWM=; b=H3o8kW1n4GwmI1 Zd8Qu4IOukqBRPLM63/WO7Kgw6guccg1iyVCrUMmbfxwZyqBPgQTjK7bVbHN9WNsQ8HBYyBagDSSm snCNnD35KC81dprTKkHOuHg8Qgnn+Ou3auuZcRw/tyPT7G6ytIRIM7nEeCNklnNVlCzili3TABEgP M06DLk/YVdjbJqH86uAYWn6bQ9RLtJ+od5vBd4j6nkScWek0IKuJ8DI9SnB8nIyWEhNbR8ZnyKQny 4iAzxhPsRKLY9U7qgwNwGjmLClPXk5uSvxKsfDluIcW7Jtn1jZCas1rhXgsd9e1GVX8Z0ewNRRZvt yTkXYWeVmSg8UVY0SO6A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mL1BI-0024H4-HN; Tue, 31 Aug 2021 10:39:52 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mL1BF-0024GE-CE for openwrt-devel@lists.openwrt.org; Tue, 31 Aug 2021 10:39:50 +0000 Received: by mail-wm1-x335.google.com with SMTP id m25-20020a7bcb99000000b002e751bcb5dbso2145122wmi.5 for ; Tue, 31 Aug 2021 03:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netduma-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w5CjQqrAZr3Q1Kwi4YYkUDI+3FOStNykUCSSXcxFmgA=; b=0oNNMGrFz6J5qtx0EvvflwBCM0W0FjBJCTg5xcw4OUXhsTo6DEnJjUzMpYNn3o4bKI u4bKdAKn+o7jbW0/AnllZbg2VUFFrFVaZ+9FfMFveg1iyLSLXZrZmlZPmo7QGRYmY5aq fuJenH7rNF5M5xvfOoBhZB4e95D03rkw26iK4QgMdE/hzci7Ef3qxzrXoLBlZtK1/pZu dR7BJRuhLqvlh5I/lJTECcQP3xmcy5iLD0CeN/6k5LOPw9Uz7alEN7UhwUw21oqe+JsE cCSbcPPAxoTCz9qadDd2GwCIEPw3aBgkmeW/guL5J40fIg31sIbLILvG8pnGT/00WVL3 Osrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=w5CjQqrAZr3Q1Kwi4YYkUDI+3FOStNykUCSSXcxFmgA=; b=Xre5FMnrM91fAodoUlro3ryTO4NyZ6Tl2BFP21ddS5n0/al2duGwxJtho/2APCxyqb 0r+h6i3oTg3REdgTPNpYqwxPX/OmbS47f5MEwZweaGCp6zDR16JZYGwfMDAp0mpmb1iy 83nE+08EEWXlLF3MC5D++o9OpSLaCZ9o8lqvpZUGiUgk+/C177bz5bafSRIhO0FC1qkE 12zhIEo7c0KpgI9W0eBs8lSEni7lUx9Yep3J2t3IwUNDpbg6U4a+kPO+yUubVb+dPyXp B5rsVaavUlNkkOzwA5l4GQ+bg3iy95KZ945Pbyy28IcwEG6LIxStv88M3aBu7pDSnXkf OUUA== X-Gm-Message-State: AOAM533fQKjvkhMGUugB/8ddJF4+8UvRTEqatJwqnYhCvHcdtowJ1ZbU gIREOFCGe3AkWmjxfe2b3LmFnkzzjVHiki3g X-Google-Smtp-Source: ABdhPJyQdVBAZG3DockCaVvTTBtItvO1jHREPn5AvFmqWz+Ap7erijy2M7qTRMEKRiBOAE4jJvbsAw== X-Received: by 2002:a1c:7506:: with SMTP id o6mr3623761wmc.112.1630406386767; Tue, 31 Aug 2021 03:39:46 -0700 (PDT) Received: from lin-dev-002.ipa.internal.netduma.com ([77.95.36.54]) by smtp.gmail.com with ESMTPSA id d7sm18240103wrs.39.2021.08.31.03.39.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 03:39:46 -0700 (PDT) From: adrian.frances@netduma.com To: openwrt-devel@lists.openwrt.org Cc: Adrian Frances Subject: [PATCH] ubus/lua: avoid changing key type to string Date: Tue, 31 Aug 2021 11:39:31 +0100 Message-Id: <20210831103931.6671-1-adrian.frances@netduma.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210831_033949_464927_A04D6463 X-CRM114-Status: GOOD ( 11.15 ) X-Spam-Score: 0.7 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Adrian Frances According to the lua man page for lua_next, it is not advised to call lua_tolstring when iterating through a table with lua_next. When iterating a table in ubus_lua_format_blob_array, we end up calling lua_tostring, which inside calls lua_tolstring, converting all non-string keys to a key format, even for the caller. Content analysis details: (0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:335 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.7 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Adrian Frances According to the lua man page for lua_next, it is not advised to call lua_tolstring when iterating through a table with lua_next. When iterating a table in ubus_lua_format_blob_array, we end up calling lua_tostring, which inside calls lua_tolstring, converting all non-string keys to a key format, even for the caller. This patch fixes the issue by restoring the original key Signed-off-by: Adrian Frances --- lua/ubus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/ubus.c b/lua/ubus.c index e2bb081..d949aea 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -184,7 +184,9 @@ ubus_lua_format_blob(lua_State *L, struct blob_buf *b, bool table) { void *c; bool rv = true; - const char *key = table ? lua_tostring(L, -2) : NULL; + lua_pushvalue(L,-2); + const char *key = table ? lua_tostring(L, -1) : NULL; + lua_pop(L,1); switch (lua_type(L, -1)) {