From patchwork Wed Jun 15 14:10:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: olivier.hardouin@gmail.com X-Patchwork-Id: 635891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rV7kz33pcz9t1J for ; Thu, 16 Jun 2016 00:12:43 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=pt2VAYFx; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bDBXL-0002lD-R0; Wed, 15 Jun 2016 14:11:19 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1bDBXG-0002dK-6B for lede-dev@lists.infradead.org; Wed, 15 Jun 2016 14:11:14 +0000 Received: by mail-lf0-x241.google.com with SMTP id l188so1633616lfe.0 for ; Wed, 15 Jun 2016 07:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1r5/w4E64ZKQGZKkeSqq/p0pUkeoW7jt7eCUlOgOysw=; b=pt2VAYFxpVy5uqulM6ttw1QSDFjDnxV+0jF8JG1Uzg9SHgIjxVe/WTDsJ0/dYqBXe7 eBwm+bAiIqxzl8Y477FtvHteK+DIDbOe/3465NHMHlnnPPXweUddq2MAFNKWwCDybD2Z eJycHbnQxdbKlNOkAlOaBSRF4NlIfvIFfVITLMuaQO5v5qeCLGSoOzgC2zrdZD98QFPQ K6CKmmx1vm34y3dVOLJTPFaTHlKMsmdZjar/WgzXXgcSpGYlFAvIZcDfsvOp8iwQkXq1 ZQt1OeVyKSO+B6Rf95E8Q6XndhKPa/wSLVJm62vl6N4JZzkb4lOisc8WqJugXNBOUxv0 ULpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1r5/w4E64ZKQGZKkeSqq/p0pUkeoW7jt7eCUlOgOysw=; b=YnE6ocK83EhhriVSUk1uFAdAfZh3lHKYSBHqjohQr9Vunc/jbkv8/F/A2EzRS1f/Lb mGyg0ibAbOjOLrEa9UuoxjHxthFFe81OlzzkpJV24NiCuwl37Oh4bHAVVrpBaGVfS6LZ 4myk1Il6x5hopB7MKr3WFWmmxl806Qm2bhvUHdxmuvOTBEPeTV8o1eYXLppZVO+VBtro BismWXi5/iOCofDyXgC8yUPhluC24JE30wk6LufJhHUq8PUVOQQ0tSGmkgtTrFSUYTdq 7vWgBnd0d3HfwkEOOJYV3481jZpQMVNpySkBN7ZM3RR32yT9uUCjuIwqQkeZFHaJvi1M Uorw== X-Gm-Message-State: ALyK8tIq3ubTILnrG2pWQwsb/zWj/vszkZrvzsgDb4nn5UHqgMI75SggM1vVIP6/M4AxEg== X-Received: by 10.194.120.135 with SMTP id lc7mr11337806wjb.34.1465999851979; Wed, 15 Jun 2016 07:10:51 -0700 (PDT) Received: from ubuntu32bits.eu.thmulti.com ([91.183.48.131]) by smtp.gmail.com with ESMTPSA id z5sm3957366wme.5.2016.06.15.07.10.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Jun 2016 07:10:51 -0700 (PDT) From: olivier.hardouin@gmail.com To: openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Date: Wed, 15 Jun 2016 16:10:22 +0200 Message-Id: <1465999824-20936-2-git-send-email-olivier.hardouin@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465999824-20936-1-git-send-email-olivier.hardouin@gmail.com> References: <1465999824-20936-1-git-send-email-olivier.hardouin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160615_071114_419844_3BE018AB X-CRM114-Status: GOOD ( 11.21 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:241 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 (olivier.hardouin[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid Subject: [LEDE-DEV] [PATCH mountd 2/4] fix crash if no uci config file present X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Olivier Hardouin , john@phrozen.org MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org fix also possible null dereferenced pointers Signed-off-by: Olivier Hardouin --- uci.c | 6 ++++++ ucix.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/uci.c b/uci.c index f5aad02..46c3922 100644 --- a/uci.c +++ b/uci.c @@ -54,6 +54,9 @@ char* uci_get_option(struct uci_context *ctx, char *section, char *option) char *value = NULL; struct uci_ptr ptr; + if (!p) + return NULL; + memset(&ptr, 0, sizeof(ptr)); ptr.package = p->e.name; ptr.section = section; @@ -101,6 +104,9 @@ void uci_for_each_section_type(char *type, void (*cb)(char*, void*), void *priv) { struct uci_element *e; + if (!p) + return; + uci_foreach_element(&p->sections, e) if (!strcmp(type, uci_to_section(e)->type)) cb(e->name, priv); diff --git a/ucix.c b/ucix.c index e2a6780..1e4d1e6 100644 --- a/ucix.c +++ b/ucix.c @@ -18,6 +18,8 @@ static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, const cha struct uci_context* ucix_init(const char *config_file) { struct uci_context *ctx = uci_alloc_context(); + if(!ctx) + return NULL; uci_add_delta_path(ctx, "/var/state"); if(uci_load(ctx, config_file, NULL) != UCI_OK) { @@ -30,6 +32,8 @@ struct uci_context* ucix_init(const char *config_file) struct uci_context* ucix_init_path(const char *path, const char *config_file) { struct uci_context *ctx = uci_alloc_context(); + if(!ctx) + return NULL; if(path) { uci_set_savedir(ctx, path); @@ -44,7 +48,10 @@ struct uci_context* ucix_init_path(const char *path, const char *config_file) void ucix_cleanup(struct uci_context *ctx) { - uci_free_context(ctx); + if(ctx) + { + uci_free_context(ctx); + } } int ucix_save(struct uci_context *ctx, const char *p)