From c80be89ef9a51077b5bc83812b8184ff8e56bc46 Mon Sep 17 00:00:00 2001 From: sw1tchbl4d3 Date: Fri, 16 Jul 2021 00:12:12 +0200 Subject: [PATCH] Remove debug printf & use strlen() at write In sessions.h, now line 95, we used sizeof(ts_str) to determine how much to write, but as ts_str can be longer than the actual string written, it wrote random data after the actual timestamp. --- sessions.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sessions.h b/sessions.h index e4f798a..357ae4f 100644 --- a/sessions.h +++ b/sessions.h @@ -92,7 +92,7 @@ void setsession(int pid, unsigned int ts_ttl) { snprintf(ts_str, sizeof(ts_str), "%llu", (unsigned long long)time(NULL)); - if (write(fd, ts_str, sizeof(ts_str)) < 0) + if (write(fd, ts_str, strlen(ts_str)) < 0) err(1, "Could not write to %s", path); close(fd); @@ -123,7 +123,6 @@ int getsession(int pid, unsigned int ts_ttl) { err(1, "Could not open %s", path); } - printf("%d", fd); if (read(fd, ts_str, sizeof(ts_str)) < 0) err(1, "Could not read %s", path);