Skip to content

eBPF-based security platform

treewide: do without strtok() and usleep()

Daniel Borkmann31fc0fb10d0c
diff --git a/tools/shirudo-build/compile.c b/tools/shirudo-build/compile.c
index 8e232f6f..b0690a41 100644
--- a/tools/shirudo-build/compile.c
+++ b/tools/shirudo-build/compile.c
@@ -145,13 +145,13 @@ int build_compile(const char *source, const char *output,
push(argv, &n, output);
if (extra_cflags && extra_cflags[0]) {
- char *tok;
+ char *tok, *save;
cf_copy = xstrdup(extra_cflags);
if (!cf_copy)
return -ENOMEM;
- for (tok = strtok(cf_copy, " \t\n"); tok;
- tok = strtok(NULL, " \t\n")) {
+ for (tok = strtok_r(cf_copy, " \t\n", &save); tok;
+ tok = strtok_r(NULL, " \t\n", &save)) {
ret = push(argv, &n, tok);
if (ret) {
xstrfree(cf_copy);
diff --git a/util/image_runtime.c b/util/image_runtime.c
index ce526c75..b9866598 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -16,6 +16,7 @@
#include <sys/statvfs.h>
#include <sys/sysmacros.h>
#include <sys/xattr.h>
+#include <time.h>
#include <unistd.h>
#include <bpf/bpf.h>
@@ -475,7 +476,7 @@ static int remove_candidate(struct dm_verity *device)
if (ret != -EBUSY)
return ret;
if (attempt < 99)
- usleep(10000);
+ nanosleep(&(struct timespec){ .tv_nsec = 10000000 }, NULL);
}
return ret;
}
diff --git a/util/preflight.c b/util/preflight.c
index a91e8d43..6fa02d01 100644
--- a/util/preflight.c
+++ b/util/preflight.c
@@ -86,7 +86,7 @@ static void check_root(struct preflight_result *r)
static bool lsm_lists_bpf(void)
{
- char buf[1024];
+ char buf[1024], *save;
ssize_t n;
int fd;
@@ -99,7 +99,8 @@ static bool lsm_lists_bpf(void)
return false;
buf[n] = '\0';
- for (char *p = strtok(buf, ",\n"); p; p = strtok(NULL, ",\n")) {
+ for (char *p = strtok_r(buf, ",\n", &save); p;
+ p = strtok_r(NULL, ",\n", &save)) {
if (strcmp(p, "bpf") == 0)
return true;
}