From a31485da9032ce93a3c224f469b3c1b2396bbd9b Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon, 7 May 2012 15:01:58 -0300
Subject: [RHEL6 qemu-kvm PATCH 5/6] block: protect path_has_protocol from filenames with colons

RH-Author: Paolo Bonzini <pbonzini@redhat.com>
Message-id: <1336402919-26889-5-git-send-email-pbonzini@redhat.com>
Patchwork-id: 39614
O-Subject: [RHEL 6.3 qemu-kvm PATCH 4/5] block: protect path_has_protocol from filenames with colons
Bugzilla: 818876
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>

Upstream status: to be submitted, in my github blkmirror-job branch

path_has_protocol will erroneously return "true" if the colon is part
of a filename.  These names are common with stable device names produced
by udev.  We cannot fully protect against this in case the filename
does not have a path component (e.g. if the current directory is
/dev/disk/by-path), but in the common case there will be a slash before
and path_has_protocol can easily detect that and return false.

This relies on protocols not including slashes (forward or back),
which is the case anyway.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 block.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index 34dec90..a63cdd5 100644
--- a/block.c
+++ b/block.c
@@ -114,14 +114,19 @@ int is_windows_drive(const char *filename)
 /* check if the path starts with "<protocol>:" */
 static int path_has_protocol(const char *path)
 {
+    const char *p;
+
 #ifdef _WIN32
     if (is_windows_drive(path) ||
         is_windows_drive_prefix(path)) {
         return 0;
     }
+    p = path + strcspn(path, ":/\\");
+#else
+    p = path + strcspn(path, ":/");
 #endif
 
-    return strchr(path, ':') != NULL;
+    return *p == ':';
 }
 
 int path_is_absolute(const char *path)
-- 
1.7.3.2

