From patchwork Tue Jan 27 16:13:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 433568 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3473A14027A for ; Wed, 28 Jan 2015 03:14:46 +1100 (AEDT) Received: from localhost ([::1]:48240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG8mq-0008T1-Bs for incoming@patchwork.ozlabs.org; Tue, 27 Jan 2015 11:14:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG8m8-0007Ko-Ug for qemu-devel@nongnu.org; Tue, 27 Jan 2015 11:14:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YG8m4-0002ay-01 for qemu-devel@nongnu.org; Tue, 27 Jan 2015 11:14:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YG8m3-0002an-PQ; Tue, 27 Jan 2015 11:13:55 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0RGDsrH032622 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 27 Jan 2015 11:13:55 -0500 Received: from blackfin.pond.sub.org (ovpn-116-17.ams2.redhat.com [10.36.116.17]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0RGDrjZ000740 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 27 Jan 2015 11:13:54 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id BFEED30A4C15; Tue, 27 Jan 2015 17:13:52 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 27 Jan 2015 17:13:52 +0100 Message-Id: <1422375232-29283-4-git-send-email-armbru@redhat.com> In-Reply-To: <1422375232-29283-1-git-send-email-armbru@redhat.com> References: <1422375232-29283-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-trivial@nongnu.org, Paolo Bonzini Subject: [Qemu-devel] [PATCH 3/3] util/uri: URI member path can be null, compare more carfully X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org uri_resolve_relative() calls strcmp(bas->path, ref->path). However, either argument could be null! Evidence: the code checks for null after the comparison. Spotted by Coverity. I suspect this was screwed up when we stole the code from libxml2. There the conditional reads xmlStrEqual((xmlChar *)bas->path, (xmlChar *)ref->path) with int xmlStrEqual(const xmlChar *str1, const xmlChar *str2) { if (str1 == str2) return(1); if (str1 == NULL) return(0); if (str2 == NULL) return(0); do { if (*str1++ != *str2) return(0); } while (*str2++); return(1); } Fix by replicating libxml2's logic faithfully. Cc: Paolo Bonzini Signed-off-by: Markus Armbruster --- util/uri.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/uri.c b/util/uri.c index b9a7b54..1cfd78b 100644 --- a/util/uri.c +++ b/util/uri.c @@ -1935,7 +1935,8 @@ uri_resolve_relative (const char *uri, const char * base) val = g_strdup (uri); goto done; } - if (!strcmp(bas->path, ref->path)) { + if (bas->path == ref->path || + (bas->path && ref->path && !strcmp(bas->path, ref->path))) { val = g_strdup(""); goto done; }