Module: wine Branch: refs/heads/master Commit: e43cec76d1308750387a60fd200c0f179826a870 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=e43cec76d1308750387a60fd...
Author: Alexandre Julliard julliard@winehq.org Date: Mon Jun 19 22:45:28 2006 +0200
libwine: Remove one more directory level when checking for build dir.
This way it still works if the libdir we got was libs/wine instead of libs.
---
libs/wine/config.c | 42 ++++++++++++++++++++++++++---------------- 1 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/libs/wine/config.c b/libs/wine/config.c index d287c5d..b721108 100644 --- a/libs/wine/config.c +++ b/libs/wine/config.c @@ -234,12 +234,28 @@ #endif /* HAVE_GETPWUID */ init_server_dir( st.st_dev, st.st_ino ); }
+/* check if basedir is a valid build dir by checking for wineserver and ntdll */ +/* helper for running_from_build_dir */ +static inline int is_valid_build_dir( char *basedir, int baselen ) +{ + struct stat st; + + strcpy( basedir + baselen, "/server/wineserver" ); + if (stat( basedir, &st ) == -1) return 0; /* no wineserver found */ + /* check for ntdll too to make sure */ + strcpy( basedir + baselen, "/dlls/ntdll/ntdll.dll.so" ); + if (stat( basedir, &st ) == -1) return 0; /* no ntdll found */ + + basedir[baselen] = 0; + return 1; +} + /* check if we are running from the build directory */ static char *running_from_build_dir( const char *basedir, const char *bindir ) { struct stat st; const char *p; - char *path, *end; + char *path; int res;
if (!(path = build_path( bindir, "wineserver" ))) return NULL; @@ -254,24 +270,18 @@ static char *running_from_build_dir( con if (p == basedir) return NULL; path = xmalloc( p - basedir + sizeof("/dlls/ntdll/ntdll.dll.so") ); memcpy( path, basedir, p - basedir ); - end = path + (p - basedir);
- strcpy( end, "/server/wineserver" ); - if (stat( path, &st ) == -1) + if (!is_valid_build_dir( path, p - basedir )) { - free( path ); - return NULL; /* no wineserver found */ - } - - /* check for ntdll too to make sure */ - strcpy( end, "/dlls/ntdll/ntdll.dll.so" ); - if (stat( path, &st ) == -1) - { - free( path ); - return NULL; /* no ntdll found */ + /* remove another component */ + while (p > basedir && *p == '/') p--; + while (p > basedir && *p != '/') p--; + if (p == basedir || !is_valid_build_dir( path, p - basedir )) + { + free( path ); + return NULL; + } } - - *end = 0; return path; }