Skip to content

Commit 80404e9

Browse files
DeeDeeGTheAssassin
authored andcommitted
Lengthen string comparisons to unblock arm_aarch64 code path
Effectively checks that the strings being compared start and end with the specified characters (by including the terminating NUL byte of the fixed string), rather than only checking that a string *starts with* the non-null ASCII characters of the fixed string in the comparison. For example, comparing the first three characters of "pen" and "pencil" would be a match ("pen" == "pen"). Comparing the first four bytes instead, we get "pen[NUL byte]" != "penc". Prevents ambiguity between "arm" and "arm_aarch64", which makes the "arm_aarch64" code path reachable again in the large if/else of string comparisons.
1 parent 6b898b5 commit 80404e9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/appimagetool.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,29 +351,29 @@ void extract_arch_from_text(gchar *archname, const gchar* sourcename, bool* arch
351351
if (archname) {
352352
replacestr(archname, "-", "_");
353353
replacestr(archname, " ", "_");
354-
if (g_ascii_strncasecmp("i386", archname, 4) == 0
355-
|| g_ascii_strncasecmp("i486", archname, 4) == 0
356-
|| g_ascii_strncasecmp("i586", archname, 4) == 0
357-
|| g_ascii_strncasecmp("i686", archname, 4) == 0
358-
|| g_ascii_strncasecmp("intel_80386", archname, 11) == 0
359-
|| g_ascii_strncasecmp("intel_80486", archname, 11) == 0
360-
|| g_ascii_strncasecmp("intel_80586", archname, 11) == 0
361-
|| g_ascii_strncasecmp("intel_80686", archname, 11) == 0
354+
if (g_ascii_strncasecmp("i386", archname, 5) == 0
355+
|| g_ascii_strncasecmp("i486", archname, 5) == 0
356+
|| g_ascii_strncasecmp("i586", archname, 5) == 0
357+
|| g_ascii_strncasecmp("i686", archname, 5) == 0
358+
|| g_ascii_strncasecmp("intel_80386", archname, 12) == 0
359+
|| g_ascii_strncasecmp("intel_80486", archname, 12) == 0
360+
|| g_ascii_strncasecmp("intel_80586", archname, 12) == 0
361+
|| g_ascii_strncasecmp("intel_80686", archname, 12) == 0
362362
) {
363363
archs[fARCH_i686] = 1;
364364
if (verbose)
365365
fprintf(stderr, "%s used for determining architecture i386\n", sourcename);
366-
} else if (g_ascii_strncasecmp("x86_64", archname, 6) == 0) {
366+
} else if (g_ascii_strncasecmp("x86_64", archname, 7) == 0) {
367367
archs[fARCH_x86_64] = 1;
368368
if (verbose)
369369
fprintf(stderr, "%s used for determining architecture x86_64\n", sourcename);
370-
} else if (g_ascii_strncasecmp("arm", archname, 3) == 0 ||
371-
g_ascii_strncasecmp("armhf", archname, 5) == 0) {
370+
} else if (g_ascii_strncasecmp("arm", archname, 4) == 0 ||
371+
g_ascii_strncasecmp("armhf", archname, 6) == 0) {
372372
archs[fARCH_armhf] = 1;
373373
if (verbose)
374374
fprintf(stderr, "%s used for determining architecture ARM\n", sourcename);
375-
} else if (g_ascii_strncasecmp("arm_aarch64", archname, 11) == 0 ||
376-
g_ascii_strncasecmp("aarch64", archname, 7) == 0) {
375+
} else if (g_ascii_strncasecmp("arm_aarch64", archname, 12) == 0 ||
376+
g_ascii_strncasecmp("aarch64", archname, 8) == 0) {
377377
archs[fARCH_aarch64] = 1;
378378
if (verbose)
379379
fprintf(stderr, "%s used for determining architecture ARM aarch64\n", sourcename);

0 commit comments

Comments
 (0)