Hi,
I wanted to understand how the pledge execpromises commit worked in ldd
and went to read it, and noticed that there is both a
if (read(fd, &ehdr, sizeof(ehdr)) < 0) {
and a
if (pread(fd, phdr, size, ehdr.e_phoff) != size) {
In particular, the "read < 0" confused me quite a lot, but the manpage
states that, if the file descriptor _is a regular file_ and there are
enough bytes, it reads to completion. The check for a being a regular
file is already in place, but there is nothing guarding against a short
file, so check instead if read == sizeof(ehdr).
-Lucas
diff refs/heads/master 7e3ddbbb1ef48b81704d0e34d128de01a109fa8c
commit - d50cee607213855e35b101e74926cd801369edd4
commit + 7e3ddbbb1ef48b81704d0e34d128de01a109fa8c
blob - 9e8c5065cd843ff36d91efcb868b94ffd4c98365
blob + ad624d9cd0e72944b93e951de9b31f57a6258601
--- libexec/ld.so/ldd/ldd.c
+++ libexec/ld.so/ldd/ldd.c
@@ -118,7 +118,7 @@ doit(char *name)
return 1;
}
- if (read(fd, &ehdr, sizeof(ehdr)) < 0) {
+ if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) {
warn("read(%s)", name);
close(fd);
return 1;