ldlinux: Only append missing filename extensions
authorMatt Fleming <matt.fleming@intel.com>
Thu, 29 Nov 2012 08:47:15 +0000 (08:47 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Thu, 29 Nov 2012 08:47:15 +0000 (08:47 +0000)
Don't append an extension like ".c32" if the command already has one!
This bug lead to "config.c32" being executed as "config.c32.c32" with
the below config snippet,

    LABEL config
        COM32 config.c32 /configs/isolinux.cfg

Reported-by: Ady <ady-sf@hotmail.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
com32/elflink/ldlinux/ldlinux.c

index 82d2ae6..62db2f7 100644 (file)
@@ -121,12 +121,15 @@ const char *apply_extension(const char *kernel, const char *ext)
        memcpy(k, kernel, len);
 
        /* Append the extension */
-       memcpy(k + len, ext, elen);
+       if (strncmp(p - elen, ext, elen)) {
+               memcpy(k + len, ext, elen);
+               len += elen;
+       }
 
        /* Copy the rest of the command line */
-       strcpy(k + len + elen, p);
+       strcpy(k + len, p);
 
-       k[len + elen + strlen(p)] = '\0';
+       k[len + strlen(p)] = '\0';
 
        return k;
 }