From patchwork Mon Feb 1 09:56:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 576440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 91DB214056B for ; Mon, 1 Feb 2016 21:09:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=NHHsBc+m; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2DA4728BEE1; Mon, 1 Feb 2016 11:00:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) 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 version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id AA7A928BE1C for ; Mon, 1 Feb 2016 10:58:31 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Mon, 1 Feb 2016 10:58:23 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id l66so8281149wml.2 for ; Mon, 01 Feb 2016 01:58:24 -0800 (PST) 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=HsEwTbQ1dL0VuXWM/HpldMv49kmObiT3R6ltbpctOG8=; b=NHHsBc+mRpk+P4soY5Z30MdojbRwleLmy7k8DhypKsqsnndUxo9AtOZ4AWkJ40lMDa n+zlyN2J6Uy3uFM/hnjKOWqhSw0UMrb/axhbAx9nULJQSiz7/wLl+0Q4SmOcnL0C9SsW Up6YlpZW4/DHRisi+Neibhqy1VaJhCQk2SFMR+BwXJDDT22JcH+R+eUqk3/OxQOAAx5l daD1woK4+aINGtXFeZmPlB5XrcD4TGPIrEmeDh1cYGi4A4X9E7H/g0gQuxoqJLtQUO6i zjqY7lc2btxnYkrdUlVvxKPiH0okmSU+Yb7EjagVpyl6bIlf/5kb41kviCj2kyqvzyXm B8mw== 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=HsEwTbQ1dL0VuXWM/HpldMv49kmObiT3R6ltbpctOG8=; b=iGf7YpxI9M5iNe7HXcR3cCJEfr/2iI/Tdlww4p5vBFq+oYuDNQD627bELp7hMjOWZ2 xkNp8AH8ee8pdZB1FL+wAFJVYCJ9914iM+rl/QRb4jaJEV9nGAq8DtHdzwbrugVZaYIp jsCzcW+7an8zip/4kPNd5QkpJVgnjqLqhPAun6KL/kWzMTcvoZHoQpY1wE/nlHCUu9bD yKheJS3blSliiVMAY1kAr5v6qSjThr4ifh2gVF5/o7nib7SxzSEbMAxfdQK7FB6jSwoj 61OghLpCvytXCi0GHSTt9oX20IT3jNQHDt6fQAFyJhs2EXUTql3njj2UbctdrzByOdFt SMAA== X-Gm-Message-State: AG10YORmftb+221sfO/O0gf9sCo9svnS6sxLYvxpfb9Rz51GNBla8HVkZFVwL3DPxJSSSw== X-Received: by 10.28.227.6 with SMTP id a6mr10421589wmh.68.1454320676566; Mon, 01 Feb 2016 01:57:56 -0800 (PST) Received: from cplx43.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id m67sm8118759wma.10.2016.02.01.01.57.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 01 Feb 2016 01:57:55 -0800 (PST) From: Hans Dedecker To: openwrt-devel@lists.openwrt.org Date: Mon, 1 Feb 2016 10:56:30 +0100 Message-Id: <1454320590-20710-16-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454320590-20710-1-git-send-email-dedeckeh@gmail.com> References: <1454320590-20710-1-git-send-email-dedeckeh@gmail.com> Cc: Hans Dedecker , cyrus@openwrt.org Subject: [OpenWrt-Devel] [PATCH netifd 16/16] device: Fix null pointer derefence if device is unset X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 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 null pointer deference in device_claim if device is unset in device_user struct. Typically this is observed when the parent device is removed from (mac)vlan device config followed by a network reload Signed-off-by: Hans Dedecker --- device.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/device.c b/device.c index 3404fee..9344e1b 100644 --- a/device.c +++ b/device.c @@ -333,6 +333,9 @@ int device_claim(struct device_user *dep) if (dep->claimed) return 0; + if (!dev) + return -1; + dep->claimed = true; D(DEVICE, "Claim %s %s, new active count: %d\n", dev->type->name, dev->ifname, dev->active + 1); if (++dev->active != 1) @@ -721,12 +724,16 @@ device_apply_config(struct device *dev, const struct device_type *type, free(dev->config); dev->config = config; if (change == DEV_CONFIG_RESTART && dev->present) { + int ret = 0; + device_set_present(dev, false); if (dev->active && !dev->external) { - dev->set_state(dev, false); - dev->set_state(dev, true); + ret = dev->set_state(dev, false); + if (!ret) + ret = dev->set_state(dev, true); } - device_set_present(dev, true); + if (!ret) + device_set_present(dev, true); } break; case DEV_CONFIG_NO_CHANGE: