diff --git a/sessions.h b/sessions.h index 357ae4f..28108f1 100644 --- a/sessions.h +++ b/sessions.h @@ -18,6 +18,10 @@ int getpstartts(int pid, unsigned long long* startts) { err(1, "Could not open %s", path); int bytes_read = read(fd, fc, sizeof(fc)); + if (bytes_read < 0) + err(1, "Could not read %s", path); + fc[bytes_read] = '\0'; + close(fd); if (memchr(ptr, '\0', bytes_read) != NULL) @@ -123,8 +127,10 @@ int getsession(int pid, unsigned int ts_ttl) { err(1, "Could not open %s", path); } - if (read(fd, ts_str, sizeof(ts_str)) < 0) + int bytes_read = read(fd, ts_str, sizeof(ts_str)); + if (bytes_read < 0) err(1, "Could not read %s", path); + ts_str[bytes_read] = '\0'; startts = strtoull(ts_str, NULL, 10); current = time(NULL);