From patchwork Sun Feb 18 12:46:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874860 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (helo) smtp.helo=arrakis.dune.hu (client-ip=78.24.191.176; helo=arrakis.dune.hu; envelope-from=openwrt-devel-bounces@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lTh5DcqG"; dkim-atps=neutral Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zkmrC5SFnz9sWg for ; Sun, 18 Feb 2018 23:47:55 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CF659B9138B; Sun, 18 Feb 2018 13:46:59 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Sun, 18 Feb 2018 13:46:59 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 5BCB3B9126F for ; Sun, 18 Feb 2018 13:46:48 +0100 (CET) X-policyd-weight: using cached result; rate: -7 Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 18 Feb 2018 13:46:48 +0100 (CET) Received: by mail-lf0-f65.google.com with SMTP id h78so9631669lfg.6 for ; Sun, 18 Feb 2018 04:46:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FaoNt8TC1aC0Z1R9ZmP8g1ppGE1l5Zht25uZaJBYYuU=; b=lTh5DcqGlZ9BoMuIswTyvsxM6xn3IMzHkRZNzTvs+QLHRecGCuFMZf+o4t15FEIzzB H8UOelB9L2zv2sj23JGeTvb+9CIz+134YtIwddrc0QwYuImyYftDxQKSm+aP6Rx3D1xz kIY3tIZ0uXAte8+kbZE2wKiGR36SUKe8Vn19vMe+o0qs4qQTVof7Tp/M9u8wFyMtUG3r BxcwpcjDXaXtSD7L+Mk06ic1z1W6oDAAy2sytEU4bg5N+kLJts2J1Ti+/uLQFBPEakMW uHvE7UAA259RlKVKA7GkuaB8xSL1CcfWHf5N7pNkn0T3Wsc0NxH7aBrPN5vfrHpJR4ER 9caw== 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:in-reply-to :references; bh=FaoNt8TC1aC0Z1R9ZmP8g1ppGE1l5Zht25uZaJBYYuU=; b=YZO26ZW4bn2cOvEuZ6zSGdFDXhbAYgPE/W4irFO8HmSooGDT24wNi7gPZdTHl2dd4o 8Cbpc2F+HrY0mlNvBUJxaRwMJIbMcmP93iPXKgpoAg76Qz6GGsjWte/LedXvjkBf2auZ Z/lBbf2lpqbgnQvDNTr/y8+tGRw6RSw51i1dYSg4x7jGRH77CWkgflkGZspQBcpWgAt2 5fao1fiz+/Ldds+g6ficmNO996zG9NxGMRDgKaUEaIEfEQR06zjKAkhUt2EGDZ5HE4JU Z/hcdMqO7z/VPJ+d33mZBIEqqLyqZp8GTC/KppYVuT5suC2k+PAPqXrDhFFG45wYiNMH vKew== X-Gm-Message-State: APf1xPDI+g6Nk4bTClHGeW1pECN2P4ASAS22boNXzGIRW19/kpYvBawH P+9U92i4C4rCdV8fJKHTLq8gzSLj X-Google-Smtp-Source: AH8x227p8I+JhzVl4l1ZbbltdgeIQyp1JVEarkZgrLttANn5kcJT9jx56PoLquIbhpvlkdYnGVfFVQ== X-Received: by 10.25.202.9 with SMTP id a9mr8356118lfg.144.1518958007424; Sun, 18 Feb 2018 04:46:47 -0800 (PST) Received: from sunsetshimmer.lan ([2a02:8108:17c0:1500:f666:aee7:edff:2dfc]) by smtp.gmail.com with ESMTPSA id s1sm3176923ljd.13.2018.02.18.04.46.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:46 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:07 +0100 Message-Id: <20180218124610.32692-5-tobleminer@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180218124610.32692-1-tobleminer@gmail.com> References: <20180218124610.32692-1-tobleminer@gmail.com> Subject: [OpenWrt-Devel] [PATCH v2 4/7] uclient-http: Implement error handling for header-sending X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Add some error handling for errors during assembly of headers Signed-off-by: Tobias Schramm --- uclient-http.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/uclient-http.c b/uclient-http.c index 20b8a9a..04f16a3 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -568,36 +568,36 @@ fail: return err; } -static void +static int uclient_http_add_auth_header(struct uclient_http *uh) { if (!uh->uc.url->auth) - return; + return 0; switch (uh->auth_type) { case AUTH_TYPE_UNKNOWN: case AUTH_TYPE_NONE: break; case AUTH_TYPE_BASIC: - uclient_http_add_auth_basic(uh); - break; + return uclient_http_add_auth_basic(uh); case AUTH_TYPE_DIGEST: - uclient_http_add_auth_digest(uh); - break; + return uclient_http_add_auth_digest(uh); } + + return 0; } -static void +static int uclient_http_send_headers(struct uclient_http *uh) { struct uclient_url *url = uh->uc.url; struct blob_attr *cur; enum request_type req_type = uh->req_type; bool literal_ipv6; - int rem; + int err, rem; if (uh->state >= HTTP_STATE_HEADERS_SENT) - return; + return 0; if (uh->uc.proxy_url) url = uh->uc.proxy_url; @@ -620,11 +620,14 @@ uclient_http_send_headers(struct uclient_http *uh) if (uclient_request_supports_body(uh->req_type)) ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n"); - uclient_http_add_auth_header(uh); + if ((err = uclient_http_add_auth_header(uh))) + return err; ustream_printf(uh->us, "\r\n"); uh->state = HTTP_STATE_HEADERS_SENT; + + return 0; } static void uclient_http_headers_complete(struct uclient_http *uh) @@ -1020,12 +1023,14 @@ uclient_http_set_header(struct uclient *cl, const char *name, const char *value) static int uclient_http_send_data(struct uclient *cl, const char *buf, unsigned int len) { + int err; struct uclient_http *uh = container_of(cl, struct uclient_http, uc); if (uh->state >= HTTP_STATE_REQUEST_DONE) return -1; - uclient_http_send_headers(uh); + if ((err = uclient_http_send_headers(uh))) + return err; if (len > 0) { ustream_printf(uh->us, "%X\r\n", len); @@ -1039,12 +1044,15 @@ uclient_http_send_data(struct uclient *cl, const char *buf, unsigned int len) static int uclient_http_request_done(struct uclient *cl) { + int err; struct uclient_http *uh = container_of(cl, struct uclient_http, uc); if (uh->state >= HTTP_STATE_REQUEST_DONE) return -1; - uclient_http_send_headers(uh); + if ((err = uclient_http_send_headers(uh))) + return err; + if (uclient_request_supports_body(uh->req_type)) ustream_printf(uh->us, "0\r\n\r\n"); uh->state = HTTP_STATE_REQUEST_DONE;