From ca2467a4c44ad8e914fdee196571e13608fc5277 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Tue, 20 Dec 2022 22:19:39 -0600 Subject: [PATCH] roken: Do not use net_read() for regular files! The bug fixed herein almost certainly means that PKINIT was never working on Windows, since lib/hx509 uses rk_undumpdata() to read regular files containing certificates and keys, but then since rk_undumpdata() was using net_read(), that can't have worked. On Windows net_read() insists on the FD being a socket, and because of winsock, the namespaces of socket and file descriptors on Windows are distinct. --- lib/roken/dumpdata.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/roken/dumpdata.c b/lib/roken/dumpdata.c index 252744e28..11f2298ba 100644 --- a/lib/roken/dumpdata.c +++ b/lib/roken/dumpdata.c @@ -71,6 +71,9 @@ rk_undumpdata(const char *filename, void **buf, size_t *size) ret = errno; goto out; } + + if (sb.st_size < 0) + sb.st_size = 0; *buf = malloc(sb.st_size); if (*buf == NULL) { ret = ENOMEM; @@ -78,7 +81,7 @@ rk_undumpdata(const char *filename, void **buf, size_t *size) } *size = sb.st_size; - sret = net_read(fd, *buf, *size); + sret = read(fd, *buf, *size); if (sret < 0) ret = errno; else if (sret != (ssize_t)*size)