From: Tor Lillqvist Date: Wed, 21 Oct 2009 12:31:34 +0000 (+0300) Subject: Use multi-byte string functions on Windows X-Git-Tag: dbus-1.3.1~165 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db7717869a0f500a934e0b838955411eb8d10b4f;p=thirdparty%2Fdbus.git Use multi-byte string functions on Windows Don't walk through char arrays that contain strings in the system codepage char by char looking for '\\'. There are double-byte characters in East Asian codepages where the second byte is a '\\'. (cherry picked from commit 61316262da466993abbcba010c6bac90bb0b1d43) --- diff --git a/dbus/dbus-sysdeps-win.c b/dbus/dbus-sysdeps-win.c index 0cc779025..2a2619d62 100644 --- a/dbus/dbus-sysdeps-win.c +++ b/dbus/dbus-sysdeps-win.c @@ -62,6 +62,7 @@ extern BOOL WINAPI ConvertSidToStringSidA (PSID Sid, LPSTR *StringSid); #include #include +#include #include #include #include @@ -3296,26 +3297,29 @@ _dbus_get_install_root(char *prefix, int len) char* p = 0; int i; DWORD pathLength; - int lastSlash; + char *lastSlash; SetLastError( 0 ); pathLength = GetModuleFileName(NULL, prefix, len); if ( pathLength == 0 || GetLastError() != 0 ) { *prefix = '\0'; return FALSE; } - lastSlash = -1; - for (i = 0; i < pathLength; ++i) - if (prefix[i] == '\\') - lastSlash = i; - if (lastSlash == -1) { + lastSlash = _mbsrchr(prefix, '\\'); + if (lastSlash == NULL) { *prefix = '\0'; return FALSE; } //cut off binary name - prefix[lastSlash+1] = 0; + lastSlash[1] = 0; + //cut possible "\\bin" - if (lastSlash > 3 && strncmp(prefix + lastSlash - 4, "\\bin", 4) == 0) - prefix[lastSlash-3] = 0; + + //this fails if we are in a double-byte system codepage and the + //folder's name happens to end with the *bytes* + //"\\bin"... (I.e. the second byte of some Han character and then + //the Latin "bin", but that is not likely I think... + if (lastSlash - prefix > 3 && strncmp(lastSlash - 4, "\\bin", 4) == 0) + lastSlash[-3] = 0; return TRUE; }