elflink: Don't use strcmp on a non-NUL terminated string
authorMatt Fleming <matt.fleming@intel.com>
Thu, 1 Mar 2012 17:23:57 +0000 (17:23 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Fri, 23 Mar 2012 16:56:15 +0000 (16:56 +0000)
The syslinux implementation of strcmp() only checks for NUL in the
first argument and will use any NULs in the second argument for
comparison with the corresponding character in the first string. This
caused problems because at the time strcmp() is called 'path' isn't
NUL-terminated. Since we're only checking the first character of
'path' just code it explicitly.

This bug caused some modules not to load when resolving module
dependencies via the ELF DT_NEEDED field because the "." in the PATH
lookup code wouldn't be expanded to the current working directory. For
example, instead of expanding to "/foo/bar" if /foo was the cwd, the
path would be ".bar".

Signed-off-by: Matt Fleming <matt.fleming@intel.com>
com32/lib/sys/module/common.c

index b22e9c8..e26163f 100644 (file)
@@ -74,7 +74,7 @@ again:
        if (*p == ':')
                p++;
 
-       if (!strcmp(path, ".")) {
+       if (path[0] == '.' && i == 1) {
                if (!core_getcwd(path, sizeof(path))) {
                        DBG_PRINT("Could not get cwd\n");
                        return NULL;