build system: prevent duplicate applet names
authorRon Yorston <rmy@pobox.com>
Sun, 25 Nov 2018 11:46:39 +0000 (11:46 +0000)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 27 Nov 2018 09:47:06 +0000 (10:47 +0100)
The embedded script feature makes it easier to create applets with
duplicate names.  Currently in such cases the build succeeds but
the resulting executable doesn't work as the developer intended.

Catch duplicate names when the applet tables are being generated
and make the build fail.

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
applets/applet_tables.c

index e3d10c83f1b946ded744b5a0c537d3fa58d749db..ce20374407280e6a4250b76faa465d7e667edd67 100644 (file)
@@ -84,7 +84,15 @@ int main(int argc, char **argv)
 
        qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
 
-       if (!argv[1])
+       for (i = j = 0; i < NUM_APPLETS-1; ++i) {
+               if (cmp_name(applets+i, applets+i+1) == 0) {
+                       fprintf(stderr, "%s: duplicate applet name '%s'\n", argv[0],
+                                       applets[i].name);
+                       j = 1;
+               }
+       }
+
+       if (j != 0 || !argv[1])
                return 1;
        snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
        i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);