if (n < 0 || n >= (int)sizeof path)
return -1;
- if ((fd = open(path, O_RDONLY)) == -1) {
+ if ((fd = open(path, O_RDONLY|O_NOFOLLOW)) == -1) {
warn("failed to open: %s", path);
return -1;
}
- while ((n = read(fd, p, buf + sizeof buf - p)) != 0) {
+ while ((n = read(fd, p, buf + (sizeof buf - 1) - p)) != 0) {
if (n == -1) {
if (errno == EAGAIN || errno == EINTR)
continue;
return -1;
}
p += n;
- if (p >= buf + sizeof buf)
+ if (p >= buf + (sizeof buf - 1))
break;
}
close(fd);
/* error if it contains NULL bytes */
- if (n != 0 || memchr(buf, '\0', p - buf)) {
+ if (n != 0 || memchr(buf, '\0', p - buf - 1) != NULL) {
warn("NUL in: %s", path);
return -1;
+ }
+
+ *p = '\0';
/* Get the 7th field, 5 fields after the last ')',
* (2th field) because the 5th field 'comm' can include
if (fstat(fd, &st) == -1)
err(1, "fstat");
+ if (st.st_uid != 0 || st.st_gid != getgid() || st.st_mode != (S_IFREG | 0000))
+ errx(1, "timestamp uid, gid or mode wrong");
if (!timespecisset(&st.st_atim) || !timespecisset(&st.st_mtim)) {
warnx("timestamp atim or mtime not set");
if (timestamp_path(path, sizeof path) == -1)
return -1;
- if (stat(path, &st) != -1 && (st.st_uid != 0 || st.st_gid != getgid()|| st.st_mode != (S_IFREG | 0000)))
- return -1;
-
fd = open(path, O_RDONLY|O_NOFOLLOW);
if (fd == -1) {
char tmp[256];