From patchwork Sun Feb 18 12:46:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874857 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="c22wY4BA"; 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 3zkmqK4hqXz9sWg for ; Sun, 18 Feb 2018 23:47:09 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 1A958B91291; Sun, 18 Feb 2018 13:46:49 +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:49 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 97137B911E4 for ; Sun, 18 Feb 2018 13:46:44 +0100 (CET) X-policyd-weight: using cached result; rate: -7 Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 18 Feb 2018 13:46:44 +0100 (CET) Received: by mail-lf0-f68.google.com with SMTP id l191so9636315lfe.1 for ; Sun, 18 Feb 2018 04:46:44 -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=AuTuAt0+o1CpOa6J56fcEWYYJoRhKmvRior2cPIcPNg=; b=c22wY4BA79KEF+5mIDhuRn2UsV2NGPK4AZFgvYtoOf92zu+WA0ZDXolUVv7+uV/k/w NYJY2PH4zdYGdxuimOEOFnLkr2YNCrPJpwLWPN9YqsTEspPiRCoEH9U7VWfd3PNUDrcW Gd9rwS80dhoh4IDBcW+dzBm/W/aRst6ftgDxcMwOJc4aG8ZNxl85ZXjH3GK5UMXoFoDr eBfBH5tWjcGJXDJH4/JXV0V2StYWOqCGUrp7a5BnznT8r64PMxMVcZvNZqMgYqvOU8Hv yxCtHIhOs/pGmInJEm+fnMblrlkIWTLsffPs7AdyzwbmGjYLctyZcP0HRjSYJoY9HtHD A6Lg== 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=AuTuAt0+o1CpOa6J56fcEWYYJoRhKmvRior2cPIcPNg=; b=feAgE16l4FJIHqJXseXhpj0j6FB9gubxwavdSyF6PVTq3ibibCubfQ8C5wlDT8JvGl MdDp+ofekGtWEkxENYIRkitWORVpEZlvT561Jm04pF4GN/DO8zdG3tmZHR+gnS5jx/wq R253uJ/ivj11idhvHn5Vx66ll3nldO4j3vRrShdXJvhCIJoXaeauFpzyZonZDibYg1vU BBvYx4CK6B5IMoqCgZo2V4wP4/scNSkqKjiMdf1KBDoi28Mb6XiVwrFzqVeshHSgM+jR Dh7A7AoL8eaZPrUqFlvpkZktlSGFC+b/o96UdfqGnYh+o15ZzyorCpnnU7nrwyBMElP4 tqgw== X-Gm-Message-State: APf1xPCHkJEb30KeI1fxMy1bvfomUZ2O7AmG14UKgF6p7kpaIHDA6+w3 OMJEPYMBA6v6/neKiDxeXxtrSax7 X-Google-Smtp-Source: AH8x227dwRpktULYqLhd/yE3iT1JiAHYApz/MZGeWuye16pXb0RZRZCDcIxAAppUqTMgeWDiaG+jQA== X-Received: by 10.25.233.154 with SMTP id j26mr8138039lfk.30.1518958003575; Sun, 18 Feb 2018 04:46:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:43 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:04 +0100 Message-Id: <20180218124610.32692-2-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 1/7] uclient-fetch: Check for nullpointer returned by uclient_get_url_filename 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" uclient_get_url_filename may return a null ptr resulting in a null ptr dereference by fprintf and open Signed-off-by: Tobias Schramm --- uclient-fetch.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/uclient-fetch.c b/uclient-fetch.c index 6961d94..38c9c53 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -122,6 +122,11 @@ static int open_output_file(const char *path, uint64_t resume_offset) } } else { filename = uclient_get_url_filename(path, "index.html"); + if (!filename) { + ret = -ENOMEM; + goto out; + } + output_file = filename; } @@ -151,6 +156,7 @@ done: free: free(filename); +out: return ret; } From patchwork Sun Feb 18 12:46:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874858 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="KPxIX0mw"; 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 3zkmqf03h8z9sWg for ; Sun, 18 Feb 2018 23:47:25 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 195BDB912C2; Sun, 18 Feb 2018 13:46:53 +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:53 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id DC27FB911E4 for ; Sun, 18 Feb 2018 13:46:45 +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:45 +0100 (CET) Received: by mail-lf0-f65.google.com with SMTP id f137so9624912lfe.4 for ; Sun, 18 Feb 2018 04:46:45 -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=4itpeRljte7Pdwjngws4z89U6Cib4nwUCo/vg0RindI=; b=KPxIX0mwUtdDwEXSqWDzxALbFGBVPyzxm/EzI5kkOMo6GGDPQBNmn32ZHShwH8oxD4 7sJtrOhhyXcdGppXTESGJsjfdjX8WJV767J1Nna0adBq8YvjQRBkHRqeC1H/zc00FH4c UJcvOxQKtX+G9fA0OvBYebR+OAq/no9qBVEGEa6v0WwS2xSbUyYVgDjtRwsCsQA5VXJp t4zFV2UcnFrBgdG2VT/i0mSjXXhSKqv3b1ZPRn/PSkRnwWLILdcOMymjL/4/GAmgLCou DzwUY+TKBVpMq9205mV45Rv02Xq4eIBukobzCoqFaaMKj6XHkXg77zd60nX8uwQH4dR4 nS3g== 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=4itpeRljte7Pdwjngws4z89U6Cib4nwUCo/vg0RindI=; b=hl4asXvsyjigH2K1TdHFJ/sUGmhcz6rhIaqSVL+KsXQ5qeD8ux2E/lyTysq+FDn24F ECIOaMbOgvBZYLRs2RCUM/zaE9DH6QmimLlMPcEF5wVBrJDK/6xB2NTKMdDRDNBDGzrG 0NChllm6mFI3QRAo7wpjl+c/c0XYWerbNRbK2QW+uqCbNRu0gGh+ch7A7hIuJWKaQ4XE DnNYkC/GGGZe+rDpUDWLtSFHPneG51Baf2sV3tlhL4xhFYNHAa7e+TY+vU21tXGsDi7K 9DLJEOIjPjJPbaJKelWTqpn+o+DycpkFgMWCw5RrhFzK25z5PZC+nKJjF45b62y5Ve3X 01wA== X-Gm-Message-State: APf1xPBGAJBCFxwf5F6rgfSRFIxzSAWHLfaanOrWLwQI44gNJfLrr48+ 0XTKyIg8ygfeXSqi6/Nwiwf1o8HH X-Google-Smtp-Source: AH8x227UouclNsFfCyJMkQ5tJFFI6FNlxbz9h2cSfXr6Uw6asmg69pTmTGao49iUj5L0FR6LgVmxAQ== X-Received: by 10.25.201.76 with SMTP id z73mr7784144lff.74.1518958004900; Sun, 18 Feb 2018 04:46:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:44 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:05 +0100 Message-Id: <20180218124610.32692-3-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 2/7] uclient-http: basic auth: Handle memory allocation failure 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" Allocation of the base64 buffer might fail, resulting in a null ptr being passed to base64_encode as a target buffer Signed-off-by: Tobias Schramm --- uclient-http.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/uclient-http.c b/uclient-http.c index ef8de98..36e2b38 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -299,7 +299,7 @@ static bool uclient_request_supports_body(enum request_type req_type) } } -static void +static int uclient_http_add_auth_basic(struct uclient_http *uh) { struct uclient_url *url = uh->uc.url; @@ -307,11 +307,16 @@ uclient_http_add_auth_basic(struct uclient_http *uh) char *auth_buf; if (auth_len > 512) - return; + return -EINVAL; auth_buf = alloca(base64_len(auth_len) + 1); + if (!auth_buf) + return -ENOMEM; + base64_encode(url->auth, auth_len, auth_buf); ustream_printf(uh->us, "Authorization: Basic %s\r\n", auth_buf); + + return 0; } static char *digest_unquote_sep(char **str) From patchwork Sun Feb 18 12:46:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874859 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="jUszT8nF"; 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 3zkmqx58Gqz9sWg for ; Sun, 18 Feb 2018 23:47:41 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 4EA7AB91387; Sun, 18 Feb 2018 13:46:56 +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:56 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 0EC9AB91249 for ; Sun, 18 Feb 2018 13:46:47 +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:46 +0100 (CET) Received: by mail-lf0-f65.google.com with SMTP id t79so9643517lfe.3 for ; Sun, 18 Feb 2018 04:46:46 -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=adwUGKFsqNArGkDSQ2CjJOKMcbI/6M3h9X/yBYR7h4s=; b=jUszT8nFzZMN/jXUeUKgZsCr/721LapG+Gj5ddHHse5CPxPKl0jjhFkrm/UEtbbeKD kjxN710F2jx2YYwGrKq31uP+zoJSctmgCVwJ5KhRkZW1CqaSMnPrZce9+remoLm4t6jQ 082hTFHWIpTg6AfPrR0Vtcf36q7jjotR7Va+Z3LAmibiHbIjF334D8en1byQT4jYzQUM bPW235/rSyFYNbvHQs4hsrZiJrVhqbjqOgxlNB9qFEHe53PpfuT+FKVm445cMk9NqBYg XryHN4zPBSkkqA6jMfwRa48JOinxlePbSzVUIe/eoGt+yy8OBiMNxuUS3Zm0elUMOgx8 ZzKg== 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=adwUGKFsqNArGkDSQ2CjJOKMcbI/6M3h9X/yBYR7h4s=; b=dV/1JemkY3LN/ZgDzsPuYggQgc52Yd+gAuM7t2xE2EkRLOwT1YfsarP6jXtBFlETlZ 0j+nbIVYjHWVO3pvYTRmz3TWAfw/f7K1x6yKtQ23UY/F4hS/mt9BrY1HuBxF0Tma10Wv LBaLZ7wTdyYDSNER+rK1xcGdgGzJPRKZc7s1iA3M4oh71zSFHTBxZ0H6lArb/dndswPJ d38SfKgDb69nBUCxG3gnyIi9Evort6GAnYQZ8l0KjPEJEYeQZiUb1rSNISax7+zBaw0j Fknk+TIi/YrbvmQkhF9gV3hwv/Y575CX/meCNCXgu6l7KtQ7l+WijZChbHt72vwJFze0 OrhQ== X-Gm-Message-State: APf1xPCps50BtMAxQq3+4HbXUvdAi3m7iVeQA52tVl/QWenwBuFC9NRZ 0s2FFCB42wBZY/qdeUry2TqrPi9e X-Google-Smtp-Source: AH8x226dqODMS5jbIUJVaAacABOOCT0iq+xSVfVrw4ok/EP9L86uuXvTUXDR0vWn6NLVAplmjil+AQ== X-Received: by 10.25.18.73 with SMTP id h70mr7662258lfi.72.1518958006158; Sun, 18 Feb 2018 04:46:46 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:45 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:06 +0100 Message-Id: <20180218124610.32692-4-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 3/7] uclient-http: auth digest: Handle multiple possible memory allocation failures 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 null pointer checks to allocation of buffers for authentication parameters Signed-off-by: Tobias Schramm --- uclient-http.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/uclient-http.c b/uclient-http.c index 36e2b38..20b8a9a 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -433,13 +433,14 @@ static void add_field(char **buf, int *ofs, int *len, const char *name, const ch *ofs = cur - *buf; } -static void +static int uclient_http_add_auth_digest(struct uclient_http *uh) { + int err = 0; struct uclient_url *url = uh->uc.url; const char *realm = NULL, *opaque = NULL; const char *user, *password; - char *buf, *next; + char *buf, *next, *buf_orig; int len, ofs; char cnonce_str[9]; @@ -454,14 +455,21 @@ uclient_http_add_auth_digest(struct uclient_http *uh) }; len = strlen(uh->auth_str) + 1; - if (len > 512) - return; + if (len > 512) { + err = -EINVAL; + goto fail; + } buf = alloca(len); + if (!buf) { + err = -ENOMEM; + goto fail; + } + strcpy(buf, uh->auth_str); /* skip auth type */ - strsep(&buf, " "); + buf_orig = strsep(&buf, " "); next = buf; while (*next) { @@ -495,8 +503,10 @@ uclient_http_add_auth_digest(struct uclient_http *uh) *dest = digest_unquote_sep(&next); } - if (!realm || !data.qop || !data.nonce) - return; + if (!realm || !data.qop || !data.nonce) { + err = -EINVAL; + goto fail_buf; + } sprintf(nc_str, "%08x", uh->nc++); get_cnonce(cnonce_str); @@ -510,10 +520,17 @@ uclient_http_add_auth_digest(struct uclient_http *uh) char *user_buf; len = password - url->auth; - if (len > 256) - return; + if (len > 256) { + err = -EINVAL; + goto fail_buf; + } user_buf = alloca(len + 1); + if (!user_buf) { + err = -ENOMEM; + goto fail_buf; + } + strncpy(user_buf, url->auth, len); user_buf[len] = 0; user = user_buf; @@ -540,7 +557,15 @@ uclient_http_add_auth_digest(struct uclient_http *uh) add_field(&buf, &ofs, &len, "opaque", opaque); ustream_printf(uh->us, "Authorization: Digest nc=%s, qop=%s%s\r\n", data.nc, data.qop, buf); + free(buf); + + return 0; + +fail_buf: + free(buf_orig); +fail: + return err; } static void 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; From patchwork Sun Feb 18 12:46:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874861 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="HGuOsyqn"; 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 3zkmrV0Pykz9sWg for ; Sun, 18 Feb 2018 23:48:09 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CB9EEB91453; Sun, 18 Feb 2018 13:47:06 +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:47:06 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CD945B912B3 for ; Sun, 18 Feb 2018 13:46:50 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .gmail. - helo: .mail-lf0-f67.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -7 Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 18 Feb 2018 13:46:49 +0100 (CET) Received: by mail-lf0-f67.google.com with SMTP id g72so9631302lfg.5 for ; Sun, 18 Feb 2018 04:46:49 -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=ix3RUFbCi2aQVEs1FhWGizNUHjyMwZVL7B4UGCFmIkY=; b=HGuOsyqniQrMKxej+q3hJyE+wuFqXQQuTqVCSe208QoMY6Uh7gArV74IW4jh0RIMij ajojGcqD97moZnPg58DQ0R6F0FD2KUDAl7gmX+aRvKG6QPUg3QtQ3VN0Ao3GbPJO+aZN R+yT7Hj7qrC2i1GxzJyJ4jWOIE2tRgcFm8VOzEjGM7SRLwmnq2nxtuzwREXqmhAAc46k MJUs7ti2jz6gPVwBzCxGALet5rtmjk8buVLdan0d1ClP96bwB93jnoQ9j864XuSUzVYc afoE7lR/atXht5sklNb0DqkQzXdmP5NT2KwYrCGVisn9zVI71CvqKbmEQzGft5bAOpUT un3Q== 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=ix3RUFbCi2aQVEs1FhWGizNUHjyMwZVL7B4UGCFmIkY=; b=n5s311X/VCask2SiNfx2IZL2sj3LbcjxmMvHHRyr7VmhjoQZ76vxyai9HXz0i1ju33 qiqLl5+oPjyl/Qw5sDyWeE65LeLvLEBPzdPMzO7/mkgIpH8Y+lx/UL43aw4pinJti+f4 y60FIYrBO8fjqhfcAj0KcRWRf8Q0/R4gVJO0Kxt1xDVeDxTqTVZxW7t7yjhNMTPGokye uiZNjbSRC4YN5sZdCkKVbvv5iePFOYq+EwsNbR5dgsxvIsNZPhAmBBdOXN90/hBCG9Ev aZpdL/60oq5VK8OaaJhcBz2jiS71C13g4auU9e8CZYa/wGtziSTlgvwZ7s8LM4XTKSMK CcNw== X-Gm-Message-State: APf1xPDiIx9rIuA1NtG1ZK2+m/nY+V3v++LS71/uamRkaXAGtVccJnyK sQonzbLmfwsquyOjKQMGKHtUVT+6 X-Google-Smtp-Source: AH8x226HWzfop3PbOTVhYS6AlaEzLfPJPklCNCfsydGQfQ7rfJWCitgYUZYXbDOC7kHpGuafuzqxQg== X-Received: by 10.25.0.19 with SMTP id 19mr4050456lfa.69.1518958008816; Sun, 18 Feb 2018 04:46:48 -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.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:48 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:08 +0100 Message-Id: <20180218124610.32692-6-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 5/7] uclient-http: Handle memory allocation failure 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 null pointer check to allocation of uclient_http struct Signed-off-by: Tobias Schramm --- uclient-http.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uclient-http.c b/uclient-http.c index 04f16a3..b6607f1 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -949,6 +949,9 @@ static struct uclient *uclient_http_alloc(void) struct uclient_http *uh; uh = calloc_a(sizeof(*uh)); + if (!uh) + return NULL; + uh->disconnect_t.cb = uclient_http_disconnect_cb; blob_buf_init(&uh->headers, 0); From patchwork Sun Feb 18 12:46:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874862 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="kLOryBrM"; 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 3zkmrm0zKSz9sWg for ; Sun, 18 Feb 2018 23:48:23 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 008ABB9146D; Sun, 18 Feb 2018 13:47:10 +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:47:09 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id DBED1B912C1 for ; Sun, 18 Feb 2018 13:46:50 +0100 (CET) X-policyd-weight: using cached result; rate: -7 Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 18 Feb 2018 13:46:50 +0100 (CET) Received: by mail-lf0-f67.google.com with SMTP id 37so9625379lfs.7 for ; Sun, 18 Feb 2018 04:46:50 -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=1QiVwKmsSrWT9AVRqWbE9r3lLzt//c9AK8lC9C7jdtQ=; b=kLOryBrMamzpVF6x/gPZAk3SenTXbcYaVdgAWlFabYiUPgt/3uwRMPaKWzJbxIYIW/ 1is6P/DesLl3iGVdgAKJHaxhMYJ7N8adTfHvSuyM1pfxdLucai4OV3FqCRoUvx3r9Z+Z ksr1Kmwktoef3YtHu8Es1CR/NGYGsiq7akdr8hUJPVovceuATiVE+GVkVk4j6vnA7rCo 1bQOnqyg9OOrYCsUP/lhHBC0D9Q2qHCSYeT1qI63hx3oEIwTtmD8nonglLfoX8BdFUJ9 rJhKPLRrcEZvyqeruBOXAxa+xTNCyodp/cnhAXy6vuzKuKhuJvkERcIPJhNBaBa5lawy CbzQ== 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=1QiVwKmsSrWT9AVRqWbE9r3lLzt//c9AK8lC9C7jdtQ=; b=o4WNHkleNoQzQdKuirNY5bf7Ad0DWJCe/55o0/ZSPYNWEZevWt68VOuzc/7PEs1SE9 rzWimALfoE/q21sqmWHDsV1xyb2aLJUXi5dtG/SAEvxYR2GxwvoXTLyVWsaZ2LumM7/L kUApC+i56sdK8PwLic6hr3sxPt9JElTArQrmYGGlLCT2hS90Yzo0HBd+i4LcPLMXp7iB 6Ax1lSmX/XcBgHE6t8IDGZxFm9spIg9tWOktE4s5dIokUkf0mgCr0pT2kqbZ9C8OKDuR I4zrDmIOHpTQss5260fbFfGSG9y9VHLShhML4qRY8w2bSQOLVErFoKBIqGqJRiCLHIDi mAhA== X-Gm-Message-State: APf1xPDZcC375VmokbryKTISm15+PoH+3YsotM+xCx44/jD5xdbFxzfy rrfS5j4+M+dbE+dyZDNwYeQOpvQV X-Google-Smtp-Source: AH8x2256Z5g1PPCxisl0bMgzATaHRNwbpVUUaRAKbkWy9U+W9ojfVNqg/QS85f2WVu5FBYrWfoa2Sg== X-Received: by 10.25.27.82 with SMTP id b79mr2100465lfb.64.1518958010076; Sun, 18 Feb 2018 04:46:50 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:49 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:09 +0100 Message-Id: <20180218124610.32692-7-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 6/7] uclient-utils: Handle memory allocation failure for url file name 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 null pointer check to allocation of url filename Signed-off-by: Tobias Schramm --- uclient-utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/uclient-utils.c b/uclient-utils.c index a375eea..9c4dd42 100644 --- a/uclient-utils.c +++ b/uclient-utils.c @@ -177,8 +177,13 @@ char *uclient_get_url_filename(const char *url, const char *default_name) str++; len -= str - url; - if (len > 0) - return strncpy(calloc(1, len + 1), str, len); + if (len > 0) { + char *fname = calloc(1, len + 1); + if (!fname) + return NULL; + + return strncpy(fname, str, len); + } return strdup(default_name); } From patchwork Sun Feb 18 12:46:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Schramm X-Patchwork-Id: 874863 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="TFk9/oSa"; 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 3zkms140yJz9sWh for ; Sun, 18 Feb 2018 23:48:37 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2B915B91487; Sun, 18 Feb 2018 13:47:13 +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:47:13 +0100 (CET) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 381F2B912C2 for ; Sun, 18 Feb 2018 13:46:52 +0100 (CET) X-policyd-weight: using cached result; rate: -7 Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sun, 18 Feb 2018 13:46:52 +0100 (CET) Received: by mail-lf0-f66.google.com with SMTP id t204so6978648lff.9 for ; Sun, 18 Feb 2018 04:46:52 -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=nD75dpC1yCPmGEd13arUaQojukBbcs2aR9FgtvedKWo=; b=TFk9/oSas5wI/daZk+Corg90pI/rZ50tpdweXkgJRtTpCbtakCPH6BgfxKtwrpZrhI fueM4ZPgNNX2C7sLdnN0Drj8jNFZdg2aZLIceSzMKslxQh/3d9kvSW33Fm1yh+9sRu/2 WDnkwWkKJmFgp2E5V0egKwbCqLQ3/D7XhBPGQ2sZ+VeRW2WuBMyb1gXaIqXrTM78z3rW 77bJdI++CHJKugI5Lu8CrHbuSwaL5vp0M4/h9ymAKZUEZmSStcFcf6IX33JsPPCxlCU6 qShQIuPFDQl05MDQwmU4E052zPrw5ZrvwmRXZRg38sFtIxyaaEP0lnPVF2INtyZvgqn6 Wj4g== 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=nD75dpC1yCPmGEd13arUaQojukBbcs2aR9FgtvedKWo=; b=CsorY8S2TPy4vXTLIltoMDhOOszxapCBt3xc4eFsXGwZRhH2EZbO/mE78kvYo8nXgl sRiwHWMITiMDscw4DUz9+0RUaJ9DEDhTSjJF5jEJLCV+c3gZkYkEjzdWl2YkGvP7SxvI /12VM0wT/qj2HMYPblzpqP2SZ6ywPUJKiwkazWaIahy+BU7Yzi1GG5OnEMCEMh3+DeIT pZY7RlKgMyj58vEZafjkMVHgNMwaisJB1s8CUZz76mlO2FmtlAD2oLkX6qUKfdgfzjHi M/uwHjL6ECNa37J5u/jX4rUu13CmBCdURgQINRCjfw7MpY9CorcoDTI6naumFADzXP3i 5zdA== X-Gm-Message-State: APf1xPDhIanLUvxjdkPOHZDbOnc7nHatF7bAemUKvsUZPdAVIYNYmzh8 UNDyrt2GclIWpb0+/GCCQLGkRyZU X-Google-Smtp-Source: AH8x226eIUZifdLFBSf5XCMPgzfqvMTzeA4EwUnW8ImZ0GqISECdya7nCp/yBOfN7ic1dWNSgvxzSA== X-Received: by 10.46.21.75 with SMTP id 11mr4677503ljv.58.1518958011336; Sun, 18 Feb 2018 04:46:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Feb 2018 04:46:50 -0800 (PST) From: Tobias Schramm To: openwrt-devel@lists.openwrt.org Date: Sun, 18 Feb 2018 13:46:10 +0100 Message-Id: <20180218124610.32692-8-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 7/7] uclient: Handle memory allocation failure for url 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" Check ptr to url after allocation to prevent null pointer dereference Signed-off-by: Tobias Schramm --- uclient.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uclient.c b/uclient.c index 8862b55..1137168 100644 --- a/uclient.c +++ b/uclient.c @@ -59,6 +59,9 @@ __uclient_get_url(const struct uclient_backend *backend, &uri_buf, strlen(location) + 1, &auth_buf, auth_str ? strlen(auth_str) + 1 : 0); + if (!url) + return NULL; + url->backend = backend; url->location = strcpy(uri_buf, location); if (host)