From a31485da9032ce93a3c224f469b3c1b2396bbd9b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini 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 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 RH-Acked-by: Laszlo Ersek RH-Acked-by: Eduardo Habkost 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 --- block.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) Signed-off-by: Eduardo Habkost --- 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 ":" */ 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