-/* $OpenBSD: ldd.c,v 1.24 2023/07/24 01:02:47 deraadt Exp $ */
+/* $OpenBSD: ldd.c,v 1.25 2023/08/12 13:43:22 gnezdo Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
{
Elf_Ehdr ehdr;
Elf_Phdr *phdr;
- int fd, i, size, status, interp=0;
+ size_t size;
+ int fd, i, status, interp=0;
char buf[PATH_MAX];
struct stat st;
void * dlhandle;
return 1;
}
- if (read(fd, &ehdr, sizeof(ehdr)) < 0) {
- warn("read(%s)", name);
+ if (read(fd, &ehdr, sizeof(ehdr)) != sizeof(ehdr)) {
+ warnx("%s: incomplete ELF header", name);
close(fd);
return 1;
}
size = ehdr.e_phnum * sizeof(Elf_Phdr);
if (pread(fd, phdr, size, ehdr.e_phoff) != size) {
- warn("read(%s)", name);
+ warnx("%s: incomplete program header", name);
close(fd);
free(phdr);
return 1;
-# $OpenBSD: Makefile,v 1.19 2022/08/20 14:13:48 sthen Exp $
+# $OpenBSD: Makefile,v 1.20 2023/08/12 13:43:22 gnezdo Exp $
SUBDIR+= elf hidden weak dlsym dlopen dlclose lazy
SUBDIR+= constructor
SUBDIR+= link-order edgecases initfirst
SUBDIR+= df_1_noopen randomdata subst dependencies
-SUBDIR+= init-env nodelete noload
+SUBDIR+= init-env nodelete noload ldd
install:
--- /dev/null
+# $OpenBSD: Makefile,v 1.1 2023/08/12 13:43:22 gnezdo Exp $
+
+.include <bsd.own.mk>
+
+REGRESS_TARGETS = test
+
+.include <bsd.regress.mk>
+
+CLEANFILES+=empty short
+
+.PHONY: test
+test: empty short
+ ${SHELL} ${.CURDIR}/test.sh
+
+empty:
+ touch empty
+
+short:
+ dd if=/usr/bin/ldd of=short count=128 bs=1
--- /dev/null
+#!/bin/sh -ex
+# $OpenBSD: test.sh,v 1.1 2023/08/12 13:43:22 gnezdo Exp $
+
+res=0
+
+test() {
+ if eval "$@"; then
+ echo "passed"
+ else
+ echo "FAILED"
+ res=1
+ fi
+}
+
+test "ldd empty 2>&1 | grep 'incomplete ELF header'"
+test "ldd short 2>&1 | grep 'incomplete program header'"
+
+exit $res