diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libc/net/getprotoent.c | 14 | ||||
| -rw-r--r-- | src/lib/libc/net/getservent.c | 25 |
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 | ||
| 41 | void | 43 | void |
| 42 | setprotoent_r(int f, struct protoent_data *pd) | 44 | setprotoent_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 | ||
| 41 | void | 43 | void |
| 42 | setservent_r(int f, struct servent_data *sd) | 44 | setservent_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 | } | ||
| 78 | again: | 91 | again: |
| 79 | if ((p = fgetln(sd->fp, &len)) == NULL) | 92 | if ((p = fgetln(sd->fp, &len)) == NULL) |
| 80 | return (-1); | 93 | return (-1); |
