Hi,
I have a program that constantly stalls on reading /etc/spwd.db with
SHA256File() (from sha2.h). Here is the program flow:
-------->
sha256file: Operation not permitted
on file: /etc/spwd.db
2f6574632f737077642e6462
^C
beta$ stat /etc/spwd.db
1024 78977 -rw-r----- 1 root _shadow 327856 57344 "Oct 23 14:58:27 2017" "Oct
17 13:54:38 2017" "Oct 17 13:54:38 2017" 16384 112 0 /etc/spwd.db
beta$ id
uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty), 5(operator),
20(staff), 31(guest)
<--------
I don't know what's up but my research led me to create a patch for this
function, it basically completes there what was started before because
close() can rewrite errno afaik.
If anyone has a hint as to why my SHA256File() returns with NULL and sets errno
to 0 that would really interest me. My program does no setuid or seteuid at
all! If you'd like to see the program, I can provide that but I wanted
to put preference to the patch here.
Patch (against 6.2) below signature.
-peter
Index: helper.c
===================================================================
RCS file: /cvs/src/lib/libc/hash/helper.c,v
retrieving revision 1.16
diff -u -p -u -r1.16 helper.c
--- helper.c 21 Sep 2016 04:38:57 -0000 1.16
+++ helper.c 23 Oct 2017 13:06:46 -0000
@@ -71,13 +71,17 @@ HASHFileChunk(const char *filename, char
return (NULL);
if (len == 0) {
if (fstat(fd, &sb) == -1) {
+ save_errno = errno;
close(fd);
+ errno = save_errno;
return (NULL);
}
len = sb.st_size;
}
if (off > 0 && lseek(fd, off, SEEK_SET) < 0) {
+ save_errno = errno;
close(fd);
+ errno = save_errno;
return (NULL);
}