From patchwork Tue Dec 23 20:33:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 423802 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.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 89217140082 for ; Wed, 24 Dec 2014 07:34:11 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 60E1828741D; Tue, 23 Dec 2014 21:32:07 +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.2 required=5.0 tests=BAYES_00, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, T_DKIM_INVALID autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 832ED289CA0 for ; Tue, 23 Dec 2014 21:32:04 +0100 (CET) X-policyd-weight: using cached result; rate: -8.5 Received: from mail-wi0-f182.google.com (mail-wi0-f182.google.com [209.85.212.182]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 23 Dec 2014 21:32:03 +0100 (CET) Received: by mail-wi0-f182.google.com with SMTP id h11so11892677wiw.15 for ; Tue, 23 Dec 2014 12:33:59 -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:mime-version:content-type :content-transfer-encoding; bh=SgOlcOUMDaW9bpq6z2gwUA9BSSPVkJCSPywFaMuTA7E=; b=misqAyoGx0Tby/kPcOYN4/8+YJCYR3OpjHTQC08gP115RcWqedr0fSjkqXjFdHYCGz WguZEEZTWsfJfEsjn5biaHWb4OhfnQgYqbojbUTdPNHbI5TFqeY4hOAUSOGz3+Pj9+2h tOPmdRwkSVpp4OANsslnX8CTNRAF6JpC2VGGwVUgamnqT+sqBriEIWsZXQ6PM3qTT3db v3JyBcHjni6uCH0r/sYe8f9hpPKnnkqVq781j7bK9Rxk9O40as7qZDbRG1eVlipr+o08 9JifZzA5m5a3e2PqHRQqnYZPp4JGX8uc/83gkJvuFPG91bf95mcEeCHcx3OgSFz0mHSr rTjQ== X-Received: by 10.180.210.228 with SMTP id mx4mr45460699wic.57.1419366839539; Tue, 23 Dec 2014 12:33:59 -0800 (PST) Received: from linux-tdhb.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by mx.google.com with ESMTPSA id gf6sm29032183wjc.11.2014.12.23.12.33.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Dec 2014 12:33:58 -0800 (PST) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Felix Fietkau , John Crispin Date: Tue, 23 Dec 2014 21:33:49 +0100 Message-Id: <1419366829-27051-1-git-send-email-zajec5@gmail.com> X-Mailer: git-send-email 1.8.4.5 MIME-Version: 1.0 Cc: openwrt-devel@lists.openwrt.org Subject: [OpenWrt-Devel] [PATCH fstools] libfstools: ubi: avoid crash in volume finding function 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: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" In case /sys/devices/virtual/ubi/ubi?/ubi?_?/name doesn't exist volname will be NULL and calling strlen for NULL isn't a good idea. Signed-off-by: Rafał Miłecki --- libfstools/ubi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libfstools/ubi.c b/libfstools/ubi.c index 866034a..ac9eb1b 100644 --- a/libfstools/ubi.c +++ b/libfstools/ubi.c @@ -143,6 +143,10 @@ static int ubi_volume_match(struct volume *v, char *name, int ubi_num, int volid /* todo: skip existing gluebi device for legacy support */ volname = read_string_from_file(voldir, "name"); + if (!volname) { + fprintf(stderr, "Couldn't read %s/name\n", voldir); + return -1; + } if (strncmp(name, volname, strlen(volname) + 1)) return -1;