From patchwork Thu Dec 19 22:11:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1213788 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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; dmarc=none (p=none dis=none) header.from=true.cz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qoD0Gexo"; 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 47f5kt31bPz9sPJ for ; Fri, 20 Dec 2019 09:14:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XNgFNALV3xGYeW29ijQqJMJlNndvSnXhCATT6R/Q7MY=; b=qoD0GexoWV7EQB 2g3R0Hw3ztI1MNQj5k9QRbGsfpRTuGL3touNkLMmkxgq1d/Dd+U4zxPzQNnoODAx6VU4mRZsKLcBM H1oQZLcEwmsbsSIB74Qr/Hn9T3x9sLKE2XxdyuApoD2oT7yz6zdkd8boaGwUTGhXpfJqzpVMEb5HJ zQ/doojQYLjUhoX7A+pWX8EC1Nm0+lfhtcvu4ALADBbv4J3yDvN1fxVRkfADN1pOKWw3vjsJjZUgq 7OtDCjU7EUsW5ToSWn7k3vvDvf2U8714R/lNAkdIAV3W/Jn5n1Y4mMbVBGElXYPy7wmGvtPWhxu/I 7otNKSbYBhzkjepVbCUw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii43a-0000XI-7P; Thu, 19 Dec 2019 22:14:06 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ii41L-00054u-Ch for openwrt-devel@lists.openwrt.org; Thu, 19 Dec 2019 22:11:51 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id A7ABA4BCC; Thu, 19 Dec 2019 23:11:45 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id c1d5be37; Thu, 19 Dec 2019 23:11:35 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Date: Thu, 19 Dec 2019 23:11:19 +0100 Message-Id: <20191219221125.22646-11-ynezz@true.cz> In-Reply-To: <20191219221125.22646-1-ynezz@true.cz> References: <20191219221125.22646-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191219_141147_609926_F66EC3ED X-CRM114-Status: UNSURE ( 8.25 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [178.217.244.18 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH ubus 10/16] lua: workaround false positive dereference of null pointer X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Petr_=C5=A0tetiar?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org scan-build from clang-9 has reported following: ubus.c:837:16: warning: Access to field 'rnotify' results in a dereference of a null pointer (loaded from variable 'sub') sub->rnotify = luaL_ref(L, -2); Which is false positive as the lua_error() does a long jump and therefore never returns and this long jump probably confuses the static analyzer. So this patch workarounds this false positive by helping static analyzer by using common Lua idiom which is to return lua_error()'s return value. Ref: https://www.lua.org/manual/5.1/manual.html#lua_error Addresses-Coverity-ID: 1412355 ("Dereference after null check") Signed-off-by: Petr Štetiar --- lua/ubus.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/ubus.c b/lua/ubus.c index 6fbbc0686af3..fb50418d27b0 100644 --- a/lua/ubus.c +++ b/lua/ubus.c @@ -557,8 +557,7 @@ static int ubus_lua_add(lua_State *L) /* verify top level object */ if (lua_istable(L, 1)) { lua_pushstring(L, "you need to pass a table"); - lua_error(L); - return 0; + return lua_error(L); } /* scan each object */ @@ -598,7 +597,7 @@ ubus_lua_notify( lua_State *L ) if( !lua_islightuserdata( L, 2 ) ){ lua_pushfstring( L, "Invald 2nd parameter, expected ubus obj ref" ); - lua_error( L ); + return lua_error( L ); } obj = lua_touserdata( L, 2 ); @@ -606,7 +605,7 @@ ubus_lua_notify( lua_State *L ) blob_buf_init(&c->buf, 0); if( !ubus_lua_format_blob_array( L, &c->buf, true ) ){ lua_pushfstring( L, "Invalid 4th parameter, expected table of arguments" ); - lua_error( L ); + return lua_error( L ); } ubus_notify( c->ctx, obj, method, c->buf.head, -1 ); @@ -812,7 +811,7 @@ ubus_sub_notify_handler(struct ubus_context *ctx, struct ubus_object *obj, -static void +static int ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* target, int idxnotify, int idxremove ) { @@ -822,13 +821,13 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe if( ( status = ubus_lookup_id( ctx, target, &id ) ) ){ lua_pushfstring( L, "Unable find target, status=%d", status ); - lua_error( L ); + return lua_error( L ); } sub = calloc( 1, sizeof( struct ubus_lua_subscriber ) ); if( !sub ){ lua_pushstring( L, "Out of memory" ); - lua_error( L ); + return lua_error( L ); } if( idxnotify ){ @@ -849,13 +848,15 @@ ubus_lua_do_subscribe( struct ubus_context *ctx, lua_State *L, const char* targe if( ( status = ubus_register_subscriber( ctx, &sub->s ) ) ){ lua_pushfstring( L, "Failed to register subscriber, status=%d", status ); - lua_error( L ); + return lua_error( L ); } if( ( status = ubus_subscribe( ctx, &sub->s, id) ) ){ lua_pushfstring( L, "Failed to register subscriber, status=%d", status ); - lua_error( L ); + return lua_error( L ); } + + return 0; } static int