Skip to content

Commit 3e1cb20

Browse files
retrodoodstephensmalley
authored andcommitted
libselinux: use null character with strings
Signed-off-by: Kalevi Kolttonen <kalevi@kolttonen.fi> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com>
1 parent 57cd62c commit 3e1cb20

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

libselinux/src/get_context_list.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static int get_context_user(FILE *fp, context_t fromcon, const char *user,
152152

153153
while ((len = getline(&line, &line_len, fp)) > 0) {
154154
if (line[len - 1] == '\n')
155-
line[len - 1] = 0;
155+
line[len - 1] = '\0';
156156

157157
/* Skip leading whitespace. */
158158
start = line;
@@ -175,14 +175,14 @@ static int get_context_user(FILE *fp, context_t fromcon, const char *user,
175175
start++;
176176
if (*start != ':')
177177
continue;
178-
*start = 0;
178+
*start = '\0';
179179
linetype = ++start;
180180
while (*start && !isspace((unsigned char)*start) &&
181181
*start != ':')
182182
start++;
183183
if (!(*start))
184184
continue;
185-
*start = 0;
185+
*start = '\0';
186186
if (!strcmp(fromrole, linerole) &&
187187
!strcmp(fromtype, linetype)) {
188188
found = 1;
@@ -209,7 +209,7 @@ static int get_context_user(FILE *fp, context_t fromcon, const char *user,
209209
while (*end && !isspace((unsigned char)*end))
210210
end++;
211211
if (*end)
212-
*end++ = 0;
212+
*end++ = '\0';
213213

214214
/* Check whether a new context is valid */
215215
if (SIZE_MAX - user_len < strlen(start) + 2) {
@@ -308,7 +308,7 @@ static int get_failsafe_context(const char *user, char **newcon)
308308
return -1;
309309
plen = strlen(ptr);
310310
if (plen && buf[plen - 1] == '\n')
311-
buf[plen - 1] = 0;
311+
buf[plen - 1] = '\0';
312312

313313
nlen = strlen(user) + 1 + plen + 1;
314314
*newcon = malloc(nlen);

libselinux/src/get_default_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int find_default_type(FILE *fp, const char *role, char **type)
3939
return -1;
4040
}
4141
if (buf[0] && buf[strlen(buf) - 1])
42-
buf[strlen(buf) - 1] = 0;
42+
buf[strlen(buf) - 1] = '\0';
4343

4444
ptr = buf;
4545
while (*ptr && isspace((unsigned char)*ptr))

libselinux/src/is_customizable_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void customizable_init(void)
4545
while (fgets_unlocked(buf, selinux_page_size, fp) &&
4646
i < ctr) {
4747
if (buf[0])
48-
buf[strlen(buf) - 1] = 0;
48+
buf[strlen(buf) - 1] = '\0';
4949
list[i] = strdup(buf);
5050
if (!list[i]) {
5151
unsigned int j;

libselinux/src/matchmediacon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int matchmediacon(const char *media, char **con)
2727
return -1;
2828
}
2929
if (current_line[0] && current_line[strlen(current_line) - 1])
30-
current_line[strlen(current_line) - 1] = 0;
30+
current_line[strlen(current_line) - 1] = '\0';
3131
/* Skip leading whitespace before the partial context. */
3232
ptr = current_line;
3333
while (*ptr && isspace((unsigned char)*ptr))

0 commit comments

Comments
 (0)