prevent uninitialized memory access by declaring tab array static and classify elf file by type (object, executable, shared library, core dump) Reference: /n/sources/patch/applied/file-elf Date: Tue May 23 02:08:14 CES 2006 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/file.c Tue May 23 02:06:43 2006 +++ /sys/src/cmd/file.c Tue May 23 02:06:31 2006 @@ -1244,7 +1244,7 @@ int iself(void) { - char *cpu[] = { /* NB: incomplete and arbitary list */ + static char *cpu[] = { /* NB: incomplete and arbitary list */ [1] "WE32100", [2] "SPARC", [3] "i386", @@ -1267,12 +1267,18 @@ [62] "AMD64", [75] "VAX", }; - + static char *type[] = { + [1] "relocatable object", + [2] "executable", + [3] "shared library", + [4] "core dump", + }; if (memcmp(buf, "\x7fELF", 4) == 0){ if (!mime){ int n = (buf[19] << 8) | buf[18]; char *p = "unknown"; + char *t = "unknown"; if (n > 0 && n < nelem(cpu) && cpu[n]) p = cpu[n]; @@ -1282,7 +1288,10 @@ if (n > 0 && n < nelem(cpu) && cpu[n]) p = cpu[n]; } - print("%s ELF executable\n", p); + n = buf[16]; + if(n>0 && n < nelem(type) && type[n]) + t = type[n]; + print("%s ELF %s\n", p, t); } else print("application/x-elf-executable");