Skip to content

Commit 82195e7

Browse files
cgzonesjwcart2
authored andcommitted
libselinux: use reentrant strtok_r(3)
Use the reentrant version strtok_r(3) instead of strtok(3) to avoid potential data races with concurrent threads. Signed-off-by: Christian Göttsche <cgzones@googlemail.com> Acked-by: James Carter <jwcart2@gmail.com>
1 parent 3e3661f commit 82195e7

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

libselinux/src/selinux_restorecon.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static uint64_t exclude_non_seclabel_mounts(void)
243243
int index = 0, found = 0;
244244
uint64_t nfile = 0;
245245
char *mount_info[4];
246-
char *buf = NULL, *item;
246+
char *buf = NULL, *item, *saveptr;
247247

248248
/* Check to see if the kernel supports seclabel */
249249
if (uname(&uts) == 0 && strverscmp(uts.release, "2.6.30") < 0)
@@ -258,13 +258,14 @@ static uint64_t exclude_non_seclabel_mounts(void)
258258
while (getline(&buf, &len, fp) != -1) {
259259
found = 0;
260260
index = 0;
261-
item = strtok(buf, " ");
261+
saveptr = NULL;
262+
item = strtok_r(buf, " ", &saveptr);
262263
while (item != NULL) {
263264
mount_info[index] = item;
264265
index++;
265266
if (index == 4)
266267
break;
267-
item = strtok(NULL, " ");
268+
item = strtok_r(NULL, " ", &saveptr);
268269
}
269270
if (index < 4) {
270271
selinux_log(SELINUX_ERROR,
@@ -276,14 +277,15 @@ static uint64_t exclude_non_seclabel_mounts(void)
276277
/* Remove pre-existing entry */
277278
remove_exclude(mount_info[1]);
278279

279-
item = strtok(mount_info[3], ",");
280+
saveptr = NULL;
281+
item = strtok_r(mount_info[3], ",", &saveptr);
280282
while (item != NULL) {
281283
if (strcmp(item, "seclabel") == 0) {
282284
found = 1;
283285
nfile += file_system_count(mount_info[1]);
284286
break;
285287
}
286-
item = strtok(NULL, ",");
288+
item = strtok_r(NULL, ",", &saveptr);
287289
}
288290

289291
/* Exclude mount points without the seclabel option */

0 commit comments

Comments
 (0)