From patchwork Mon Jul 27 05:07:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1336671 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=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com 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=merlin.20170209 header.b=kg7P130S; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=EonxQ0el; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 4BFSXz3LRzz9sRN for ; Mon, 27 Jul 2020 15:09:55 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject: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=9FI34SAZ47xicjJKwPLQlKyAw6d7KpU+5H5WdkN/HuI=; b=kg7P130SvfokAn8MHYGt9WQ1NK WJ6IcoRD/FpXohpgCwxDbHM6KGW8YWHQ7nn8G248/Kzm6cPTrHkrR5ZyvfVsmlMCUs0prX2IDc5oN qaomCVgk9bPLFAFUGdev+HAbBfboAUoxcDjVuvqL1D9HvrlEQqJJkhliz2tZGW5POT/ho+ZfKU2ww NChjblXFrG6Plu5hAucpbpfXN/kXgQJfCbpwpGChkbfykhKVHj8x+dj20ku9zYO0xnxnjWZgm+Bdf g8URFqQGXg2css0n4gTLgFCnODGsR+3I3xjLzQ/+SaEI+8cEtHTbJRyFAWPW6R/gzO3iF2MZ6az0Q uLodR4uQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jzvMa-0003mf-6a; Mon, 27 Jul 2020 05:07:48 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jzvMY-0003mJ-9C for openwrt-devel@lists.openwrt.org; Mon, 27 Jul 2020 05:07:47 +0000 Received: by mail-lf1-x143.google.com with SMTP id m15so7604592lfp.7 for ; Sun, 26 Jul 2020 22:07:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tQVFLNt6Rt4g101MBmqwpOQv0Jttby5WywD2tCXpuK0=; b=EonxQ0elvjdjZjG89h7tKJZ1B9Y9MuBDCWlliMOSJNeaotS7loKOcpqbTVuUtWgCSA UY0A3h4+Bxa48jrWpsAsYrjlQbiYFrCiEJm1mb3gq1N2gIryVjWHb+M1x7d49nlnzCXg hmZsHzbYQ+K8JiULEgqxr7dWc7PC+pM6HFfoe95OW/Fx6PLWwEXl6HONxcBw+nVfWiT2 ZjmK9gmFTFubtowA1vBxA717ErG+LMl4dIfKtLITbeGTeaD8Ic6u/vzVt0WC/B2KbwJf c9wwa/sv99azjRdJzHG3SbuYUG5IeqqGG3m9LOc+CjaMF4RWVRO1fWo/4a3odEq9args ZCYQ== 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=tQVFLNt6Rt4g101MBmqwpOQv0Jttby5WywD2tCXpuK0=; b=YF2Wqt4S/rqOH0DfnX3+nWESekxDpFbJUmCaYvbsmH0F4DnrSmtJ3+bWu7fvz9vMn5 /s+VLo5MGOH7qrvSJJi1wU0DYpJJ0YcsJwBKmvj+1vWaFAwPGFpYJhh+2X4ev0mCVC2O k4Sj7ttwaFkMKLNScstQUaQI7aAumUY9C0e+zlAX6+IPDjSOqAqURmJ6kD9ffRczUbkP x9tRAqGc9k3qE9p845Y+TGy7dDsMzFPBOGMkJhdjnxZaYviWt1PaRl3klQP7iCFR4eG8 56ADmmcULZ76P1MGfGrujJodoUYvB5DdHNo9aWRrc4prvSvnq8ps1jnqhqY2C36GksiL NA0A== X-Gm-Message-State: AOAM532CfzbI8WnDzHH6mb1lW0SM1EbvGnZ8oBMHqd/TN1vzqOvW/s1H 5fkIERLE2jxAED/twNHNhypycV1J X-Google-Smtp-Source: ABdhPJyPiLg2wqE6KF4i3Tuf81R41vf2ZClBR+qJfua/gus1266dFF8VqgO8t7igRNcMvFYEQNlH4w== X-Received: by 2002:ac2:5ec8:: with SMTP id d8mr10830925lfq.169.1595826462152; Sun, 26 Jul 2020 22:07:42 -0700 (PDT) Received: from localhost.localdomain (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id t10sm2122666ljg.60.2020.07.26.22.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 22:07:41 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH uhttpd] ubus: use local "blob_buf" in uh_ubus_handle_request_object() Date: Mon, 27 Jul 2020 07:07:34 +0200 Message-Id: <20200727050734.5348-1-zajec5@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200727_010746_374896_D29F2737 X-CRM114-Status: UNSURE ( 9.59 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.1 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.1 points) 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:143 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Jo-Philipp Wich Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki This follows two other functions logic: uh_ubus_send_request() and uh_ubus_allowed(). Thanks to this change global "buf" variable is used only for replies and doesn't require state tracking & reinitialization. Signed-off-by: Rafał Miłecki --- This drops extra init call from the uh_ubus_init_response(). Code now simply depends on initial init in the uh_ubus_handle_request(). --- ubus.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ubus.c b/ubus.c index 97cc1e2..97c6cda 100644 --- a/ubus.c +++ b/ubus.c @@ -194,7 +194,6 @@ static void uh_ubus_init_response(struct client *cl) struct dispatch_ubus *du = &cl->dispatch.ubus; struct json_object *obj = du->jsobj_cur, *obj2 = NULL; - blob_buf_init(&buf, 0); blobmsg_add_string(&buf, "jsonrpc", "2.0"); if (obj) @@ -517,6 +516,7 @@ static void uh_ubus_handle_request_object(struct client *cl, struct json_object struct dispatch_ubus *du = &cl->dispatch.ubus; struct rpc_data data = {}; enum rpc_error err = ERROR_PARSE; + static struct blob_buf req; uh_client_ref(cl); @@ -524,11 +524,11 @@ static void uh_ubus_handle_request_object(struct client *cl, struct json_object goto error; du->jsobj_cur = obj; - blob_buf_init(&buf, 0); - if (!blobmsg_add_object(&buf, obj)) + blob_buf_init(&req, 0); + if (!blobmsg_add_object(&req, obj)) goto error; - if (!parse_json_rpc(&data, buf.head)) + if (!parse_json_rpc(&data, req.head)) goto error; if (!strcmp(data.method, "call")) {