On Tue, Apr 21, 2026 at 02:02:28PM -0400, Steve Shockley wrote:
> > Synopsis:   rdate gets pledge error with -c option
> > Category:   user
> > Environment:
>       System      : OpenBSD 7.9
>       Details     : OpenBSD 7.9 (GENERIC.MP) #443: Sat Apr 18 21:25:46 MDT 
> 2026
>                        
> [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
> 
>       Architecture: OpenBSD.amd64
>       Machine     : amd64
> > Description:
>       Due to muscle memory I usually run 'rdate -ncv <timeserver>' to set the
> time on a new machine, even though apparently I no longer need -n or -c.
> Anyway, running 'rdate -c <timeserver>' produces an error 'rdate[17868]:
> pledge "rpath", syscall 5'.  We should probably either fix or remove -c.

This is because ntp.c attempts to open /usr/share/zoneinfo/right/UTC.
The following fixes the pledge issues. Although I don't know where
/usr/share/zoneinfo/right/ is supposed to come from and strangely I
don't see an error from failing to open this.


diff --git usr.sbin/rdate/ntp.c usr.sbin/rdate/ntp.c
index 4aed956d62f..f0d11765f79 100644
--- usr.sbin/rdate/ntp.c
+++ usr.sbin/rdate/ntp.c
@@ -151,13 +151,13 @@ ntp_client(const char *hostname, int family, struct 
timeval *new,
                /*NOTREACHED*/
        }
 
-       if (pledge("stdio inet", NULL) == -1)
-               err(1, "pledge");
-
        corrleaps = leapflag;
        if (corrleaps)
                ntpleaps_init();
 
+       if (pledge("stdio inet", NULL) == -1)
+               err(1, "pledge");
+
        s = -1;
        for (res = res0; res; res = res->ai_next) {
                s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
diff --git usr.sbin/rdate/ntpleaps.c usr.sbin/rdate/ntpleaps.c
index f38d3cf2456..307ef8814c8 100644
--- usr.sbin/rdate/ntpleaps.c
+++ usr.sbin/rdate/ntpleaps.c
@@ -86,9 +86,6 @@ ntpleaps_sub(u_int64_t *t)
        u_int64_t u;
        int r = 1;
 
-       if (ntpleaps_init() == -1)
-               return (-1);
-
        u = *t;
 
        while (i < leapsecs_num) {
diff --git usr.sbin/rdate/rdate.c usr.sbin/rdate/rdate.c
index e6c77711b4d..1d8f62f20b8 100644
--- usr.sbin/rdate/rdate.c
+++ usr.sbin/rdate/rdate.c
@@ -132,7 +132,12 @@ main(int argc, char **argv)
                err(1, "fork");
                break;
        case 0:
-               if (pledge("stdio inet dns", NULL) == -1)
+               if (corrleaps) {
+                       if (unveil("/usr/share/zoneinfo", "r") == -1)
+                               err(1, "unveil");
+                       if (pledge("stdio rpath inet dns", NULL) == -1)
+                               err(1, "pledge");
+               } else if (pledge("stdio inet dns", NULL) == -1)
                        err(1, "pledge");
 
                close(p[0]);    /* read side of pipe */

Reply via email to