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: 637045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (caladan.dune.hu [78.24.191.180]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rWMPK3XBTz9t1f for ; Sat, 18 Jun 2016 00:01:41 +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 arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 05D65B91CE9; Fri, 17 Jun 2016 16:00:05 +0200 (CEST) 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; Fri, 17 Jun 2016 16:00:05 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id CEF70B80308 for ; Wed, 15 Jun 2016 16:10:52 +0200 (CEST) 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 ; Wed, 15 Jun 2016 16:10:52 +0200 (CEST) Received: by mail-lf0-f67.google.com with SMTP id a2so1914544lfe.3 for ; Wed, 15 Jun 2016 07:10:52 -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=TMoD2HSX6jxojmVXt5QHJKKJrJDKeFH60blu5VWQpWwNsUJVVaePI56zQdYJrBd04X R6E9oZYQD/sNO/rXtQ9T9EoqRTIFALNukseNmJOEQb9uV6zHa2WMlo2N3r1vw/es6jH5 4xX2zkpCH2CNIvgGN/2OQqJVe7yd2LUC8gh3Feq4NmVwWc6Sgnc/0A7b1D7Wc7lPkTbb Q58/+PXfcXD51euPxyitjluXaihhNVOB9Afql3/kp5g7xtxuXYu7JlfGtkFIsrM1bpw3 u7L/uExR2z8uz6gQBGmy7mJYG8SYpBK/z56v1UT4ZHn9mzsYmMQZ6w7ltfYbd+aLcpBE q9Rw== X-Gm-Message-State: ALyK8tLichcxFcIdTYpYApiBvF+MwcARodkPxMxRaywD8kw0wkSlu0bRjAD6/nmWORBBMg== 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> Subject: [OpenWrt-Devel] [PATCH mountd 2/4] fix crash if no uci config file present 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" 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)