Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

genheaders: %-<width>s had been there since v6; %-*s - since v7

Please, use at least K&R C; printf had been able to left-adjust
a field for as long as stdio existed and use of '*' for variable
width had been there since v7. Yes, the first edition of K&R
didn't cover the latter feature (it slightly predates v7), but
you are using a much later feature of the language than that -
in K&R C
static char *stoupperx(const char *s)
{
...
}
would've been spelled as
static char *stoupperx(s)
char *s;
{
...
}

While we are at it, the use of strstr() is bogus - it finds the
_first_ instance of substring, so it's a lousy fit for checking
if a string ends with given suffix...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro a40612ef 65102238

+9 -20
+9 -20
scripts/selinux/genheaders/genheaders.c
··· 19 19 #include "classmap.h" 20 20 #include "initial_sid_to_string.h" 21 21 22 - #define max(x, y) (((int)(x) > (int)(y)) ? x : y) 23 - 24 22 const char *progname; 25 23 26 24 static void usage(void) ··· 44 46 45 47 int main(int argc, char *argv[]) 46 48 { 47 - int i, j, k; 49 + int i, j; 48 50 int isids_len; 49 51 FILE *fout; 50 - const char *needle = "SOCKET"; 51 - char *substr; 52 52 53 53 progname = argv[0]; 54 54 ··· 76 80 77 81 for (i = 0; secclass_map[i].name; i++) { 78 82 struct security_class_mapping *map = &secclass_map[i]; 79 - fprintf(fout, "#define SECCLASS_%s", map->name); 80 - for (j = 0; j < max(1, 40 - strlen(map->name)); j++) 81 - fprintf(fout, " "); 82 - fprintf(fout, "%2d\n", i+1); 83 + fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1); 83 84 } 84 85 85 86 fprintf(fout, "\n"); 86 87 87 88 for (i = 1; i < isids_len; i++) { 88 89 const char *s = initial_sid_to_string[i]; 89 - fprintf(fout, "#define SECINITSID_%s", s); 90 - for (j = 0; j < max(1, 40 - strlen(s)); j++) 91 - fprintf(fout, " "); 92 - fprintf(fout, "%2d\n", i); 90 + fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i); 93 91 } 94 92 fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); 95 93 fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); ··· 91 101 fprintf(fout, "\tbool sock = false;\n\n"); 92 102 fprintf(fout, "\tswitch (kern_tclass) {\n"); 93 103 for (i = 0; secclass_map[i].name; i++) { 104 + static char s[] = "SOCKET"; 94 105 struct security_class_mapping *map = &secclass_map[i]; 95 - substr = strstr(map->name, needle); 96 - if (substr && strcmp(substr, needle) == 0) 106 + int len = strlen(map->name), l = sizeof(s) - 1; 107 + if (len >= l && memcmp(map->name + len - l, s, l) == 0) 97 108 fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); 98 109 } 99 110 fprintf(fout, "\t\tsock = true;\n"); ··· 120 129 121 130 for (i = 0; secclass_map[i].name; i++) { 122 131 struct security_class_mapping *map = &secclass_map[i]; 132 + int len = strlen(map->name); 123 133 for (j = 0; map->perms[j]; j++) { 124 134 if (j >= 32) { 125 135 fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", 126 136 map->name, map->perms[j]); 127 137 exit(5); 128 138 } 129 - fprintf(fout, "#define %s__%s", map->name, 130 - map->perms[j]); 131 - for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++) 132 - fprintf(fout, " "); 133 - fprintf(fout, "0x%08xU\n", (1<<j)); 139 + fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name, 140 + 39-len, map->perms[j], 1U<<j); 134 141 } 135 142 } 136 143