summaryrefslogtreecommitdiff
path: root/src/lib/libc
diff options
context:
space:
mode:
authorderaadt <>2026-03-10 00:06:39 +0000
committerderaadt <>2026-03-10 00:06:39 +0000
commit78f85e779d20fa57aa5102634e747be7f9343cf6 (patch)
tree4e654a5f39c3d6dc90957c7b9049ba03d89fbadf /src/lib/libc
parente6b7b55ad0eccc084f5757d7c3e4380079fc99b8 (diff)
downloadopenbsd-78f85e779d20fa57aa5102634e747be7f9343cf6.tar.gz
openbsd-78f85e779d20fa57aa5102634e747be7f9343cf6.tar.bz2
openbsd-78f85e779d20fa57aa5102634e747be7f9343cf6.zip
Use __pledge_open(2) for files that libc urgently needs even in lower
promise levels. You must be running a kernel at least 4 days old. Soon, another commit will happen that breaks compatibility even further, and you'll need new static binaries and new libc.so, along with a new kernel. This removes an old pledge design decision which is weak. Long discussions with david leadbeater and beck
Diffstat (limited to 'src/lib/libc')
-rw-r--r--src/lib/libc/net/getprotoent.c14
-rw-r--r--src/lib/libc/net/getservent.c25
2 files changed, 29 insertions, 10 deletions
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c
index a218863d07..88de656fca 100644
--- a/src/lib/libc/net/getprotoent.c
+++ b/src/lib/libc/net/getprotoent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getprotoent.c,v 1.13 2015/09/14 07:38:38 guenther Exp $ */ 1/* $OpenBSD: getprotoent.c,v 1.14 2026/03/10 00:06:39 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 1983, 1993 3 * Copyright (c) 1983, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -37,13 +37,19 @@
37#include <stdio.h> 37#include <stdio.h>
38#include <stdlib.h> 38#include <stdlib.h>
39#include <string.h> 39#include <string.h>
40#include <unistd.h>
41#include <fcntl.h>
40 42
41void 43void
42setprotoent_r(int f, struct protoent_data *pd) 44setprotoent_r(int f, struct protoent_data *pd)
43{ 45{
44 if (pd->fp == NULL) 46 if (pd->fp == NULL) {
45 pd->fp = fopen(_PATH_PROTOCOLS, "re" ); 47 int fd = __pledge_open(_PATH_PROTOCOLS, O_RDONLY|O_CLOEXEC);
46 else 48 if (fd != -1)
49 pd->fp = fdopen(fd, "r" );
50 if (pd->fp == NULL)
51 close(fd);
52 } else
47 rewind(pd->fp); 53 rewind(pd->fp);
48 pd->stayopen |= f; 54 pd->stayopen |= f;
49} 55}
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c
index 220a5851ce..4d0172a2d1 100644
--- a/src/lib/libc/net/getservent.c
+++ b/src/lib/libc/net/getservent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: getservent.c,v 1.15 2015/09/14 07:38:38 guenther Exp $ */ 1/* $OpenBSD: getservent.c,v 1.16 2026/03/10 00:06:39 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 1983, 1993 3 * Copyright (c) 1983, 1993
4 * The Regents of the University of California. All rights reserved. 4 * The Regents of the University of California. All rights reserved.
@@ -37,13 +37,19 @@
37#include <stdio.h> 37#include <stdio.h>
38#include <string.h> 38#include <string.h>
39#include <stdlib.h> 39#include <stdlib.h>
40#include <unistd.h>
41#include <fcntl.h>
40 42
41void 43void
42setservent_r(int f, struct servent_data *sd) 44setservent_r(int f, struct servent_data *sd)
43{ 45{
44 if (sd->fp == NULL) 46 if (sd->fp == NULL) {
45 sd->fp = fopen(_PATH_SERVICES, "re" ); 47 int fd = __pledge_open(_PATH_SERVICES, O_RDONLY|O_CLOEXEC);
46 else 48 if (fd != -1)
49 sd->fp = fdopen(fd, "r" );
50 if (sd->fp == NULL)
51 close(fd);
52 } else
47 rewind(sd->fp); 53 rewind(sd->fp);
48 sd->stayopen |= f; 54 sd->stayopen |= f;
49} 55}
@@ -73,8 +79,15 @@ getservent_r(struct servent *se, struct servent_data *sd)
73 long l; 79 long l;
74 int serrno; 80 int serrno;
75 81
76 if (sd->fp == NULL && (sd->fp = fopen(_PATH_SERVICES, "re" )) == NULL) 82 if (sd->fp == NULL) {
77 return (-1); 83 int fd = __pledge_open(_PATH_SERVICES, O_RDONLY|O_CLOEXEC);
84 if (fd == -1)
85 return (-1);
86 if ((sd->fp = fdopen(fd, "r" )) == NULL) {
87 close(fd);
88 return (-1);
89 }
90 }
78again: 91again:
79 if ((p = fgetln(sd->fp, &len)) == NULL) 92 if ((p = fgetln(sd->fp, &len)) == NULL)
80 return (-1); 93 return (-1);