1
0
Fork 0
forked from soccera/rdo

Null-terminate read data

This commit is contained in:
sw1tchbl4d3 2021-07-16 00:35:02 +02:00
parent e1147f4c7c
commit a23bb67985

View file

@ -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);