diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2018-12-10 03:40:11 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2018-12-10 03:40:11 -0500 |
commit | a40612ef0ee1e524aafee58d0e5713cf5fdb3d62 (patch) | |
tree | d91ab06356cb2ffa1b49320127ed35a948c33d98 /scripts/selinux/genheaders/genheaders.c | |
parent | 651022382c7f8da46cb4872a545ee1da6d097d2a (diff) |
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>
Diffstat (limited to 'scripts/selinux/genheaders/genheaders.c')
-rw-r--r-- | scripts/selinux/genheaders/genheaders.c | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/scripts/selinux/genheaders/genheaders.c b/scripts/selinux/genheaders/genheaders.c index fa48fabcb330..1ceedea847dd 100644 --- a/scripts/selinux/genheaders/genheaders.c +++ b/scripts/selinux/genheaders/genheaders.c | |||
@@ -19,8 +19,6 @@ struct security_class_mapping { | |||
19 | #include "classmap.h" | 19 | #include "classmap.h" |
20 | #include "initial_sid_to_string.h" | 20 | #include "initial_sid_to_string.h" |
21 | 21 | ||
22 | #define max(x, y) (((int)(x) > (int)(y)) ? x : y) | ||
23 | |||
24 | const char *progname; | 22 | const char *progname; |
25 | 23 | ||
26 | static void usage(void) | 24 | static void usage(void) |
@@ -46,11 +44,9 @@ static char *stoupperx(const char *s) | |||
46 | 44 | ||
47 | int main(int argc, char *argv[]) | 45 | int main(int argc, char *argv[]) |
48 | { | 46 | { |
49 | int i, j, k; | 47 | int i, j; |
50 | int isids_len; | 48 | int isids_len; |
51 | FILE *fout; | 49 | FILE *fout; |
52 | const char *needle = "SOCKET"; | ||
53 | char *substr; | ||
54 | 50 | ||
55 | progname = argv[0]; | 51 | progname = argv[0]; |
56 | 52 | ||
@@ -80,20 +76,14 @@ int main(int argc, char *argv[]) | |||
80 | 76 | ||
81 | for (i = 0; secclass_map[i].name; i++) { | 77 | for (i = 0; secclass_map[i].name; i++) { |
82 | struct security_class_mapping *map = &secclass_map[i]; | 78 | struct security_class_mapping *map = &secclass_map[i]; |
83 | fprintf(fout, "#define SECCLASS_%s", map->name); | 79 | fprintf(fout, "#define SECCLASS_%-39s %2d\n", map->name, i+1); |
84 | for (j = 0; j < max(1, 40 - strlen(map->name)); j++) | ||
85 | fprintf(fout, " "); | ||
86 | fprintf(fout, "%2d\n", i+1); | ||
87 | } | 80 | } |
88 | 81 | ||
89 | fprintf(fout, "\n"); | 82 | fprintf(fout, "\n"); |
90 | 83 | ||
91 | for (i = 1; i < isids_len; i++) { | 84 | for (i = 1; i < isids_len; i++) { |
92 | const char *s = initial_sid_to_string[i]; | 85 | const char *s = initial_sid_to_string[i]; |
93 | fprintf(fout, "#define SECINITSID_%s", s); | 86 | fprintf(fout, "#define SECINITSID_%-39s %2d\n", s, i); |
94 | for (j = 0; j < max(1, 40 - strlen(s)); j++) | ||
95 | fprintf(fout, " "); | ||
96 | fprintf(fout, "%2d\n", i); | ||
97 | } | 87 | } |
98 | fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); | 88 | fprintf(fout, "\n#define SECINITSID_NUM %d\n", i-1); |
99 | fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); | 89 | fprintf(fout, "\nstatic inline bool security_is_socket_class(u16 kern_tclass)\n"); |
@@ -101,9 +91,10 @@ int main(int argc, char *argv[]) | |||
101 | fprintf(fout, "\tbool sock = false;\n\n"); | 91 | fprintf(fout, "\tbool sock = false;\n\n"); |
102 | fprintf(fout, "\tswitch (kern_tclass) {\n"); | 92 | fprintf(fout, "\tswitch (kern_tclass) {\n"); |
103 | for (i = 0; secclass_map[i].name; i++) { | 93 | for (i = 0; secclass_map[i].name; i++) { |
94 | static char s[] = "SOCKET"; | ||
104 | struct security_class_mapping *map = &secclass_map[i]; | 95 | struct security_class_mapping *map = &secclass_map[i]; |
105 | substr = strstr(map->name, needle); | 96 | int len = strlen(map->name), l = sizeof(s) - 1; |
106 | if (substr && strcmp(substr, needle) == 0) | 97 | if (len >= l && memcmp(map->name + len - l, s, l) == 0) |
107 | fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); | 98 | fprintf(fout, "\tcase SECCLASS_%s:\n", map->name); |
108 | } | 99 | } |
109 | fprintf(fout, "\t\tsock = true;\n"); | 100 | fprintf(fout, "\t\tsock = true;\n"); |
@@ -129,17 +120,15 @@ int main(int argc, char *argv[]) | |||
129 | 120 | ||
130 | for (i = 0; secclass_map[i].name; i++) { | 121 | for (i = 0; secclass_map[i].name; i++) { |
131 | struct security_class_mapping *map = &secclass_map[i]; | 122 | struct security_class_mapping *map = &secclass_map[i]; |
123 | int len = strlen(map->name); | ||
132 | for (j = 0; map->perms[j]; j++) { | 124 | for (j = 0; map->perms[j]; j++) { |
133 | if (j >= 32) { | 125 | if (j >= 32) { |
134 | fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", | 126 | fprintf(stderr, "Too many permissions to fit into an access vector at (%s, %s).\n", |
135 | map->name, map->perms[j]); | 127 | map->name, map->perms[j]); |
136 | exit(5); | 128 | exit(5); |
137 | } | 129 | } |
138 | fprintf(fout, "#define %s__%s", map->name, | 130 | fprintf(fout, "#define %s__%-*s 0x%08xU\n", map->name, |
139 | map->perms[j]); | 131 | 39-len, map->perms[j], 1U<<j); |
140 | for (k = 0; k < max(1, 40 - strlen(map->name) - strlen(map->perms[j])); k++) | ||
141 | fprintf(fout, " "); | ||
142 | fprintf(fout, "0x%08xU\n", (1<<j)); | ||
143 | } | 132 | } |
144 | } | 133 | } |
145 | 134 | ||