From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:60063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRlmU-0000Rj-8u for qemu-devel@nongnu.org; Tue, 08 May 2012 10:52:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SRlmN-0007ZS-Nb for qemu-devel@nongnu.org; Tue, 08 May 2012 10:52:49 -0400 Received: from mail-pz0-f47.google.com ([209.85.210.47]:52083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SRlmN-0007Sn-FH for qemu-devel@nongnu.org; Tue, 08 May 2012 10:52:43 -0400 Received: by mail-pz0-f47.google.com with SMTP id h21so8313251dal.34 for ; Tue, 08 May 2012 07:52:42 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 8 May 2012 16:51:48 +0200 Message-Id: <1336488722-13120-9-git-send-email-pbonzini@redhat.com> In-Reply-To: <1336488722-13120-1-git-send-email-pbonzini@redhat.com> References: <1336488722-13120-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1.1 08/22] block: protect path_has_protocol from filenames with colons List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com 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. Signed-off-by: Paolo Bonzini --- block.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 0fb188f..8eeb519 100644 --- a/block.c +++ b/block.c @@ -198,14 +198,19 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, /* 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.10.1