Hello!

Like Benoit said, monitor still needs dns all the time, but since pledge
was being called there again with dns pledge then I thought it wouldn't
abort. Taking that into consideration and looking at it a little bit
more, how about this?

I removed the first pledge in main() between the 2 switch cases and
reunified them, then considering the four codepaths below I applied the
pledges directly onto each one:

show -> "stdio" when -n, "stdio rpath dns" otherwise
flushroutes -> "stdio" when -n, "stdio rpath dns" otherwise
newroute (add/change/delete) -> always needs "stdio rpath dns"
monitor -> always needs "stdio rpath dns" (this pledge was already there
and I left it untouched)

I tried a few tests manually, and also the regress battery tests for
route and apart from a couple of "Network unreachable" none had aborted
due to incorrect pledging.

PS: I replied this directly only to Theo, but undoubtedly it needs to be
reviewed by a larger audience.

Index: route.c
===================================================================
RCS file: /cvs/src/sbin/route/route.c,v
retrieving revision 1.179
diff -u -p -u -r1.179 route.c
--- route.c     25 Oct 2015 09:37:08 -0000      1.179
+++ route.c     15 Nov 2015 18:06:02 -0000
@@ -224,17 +224,6 @@ main(int argc, char **argv)
        case K_FLUSH:
                exit(flushroutes(argc, argv));
                break;
-       }
-               
-       if (nflag) {
-               if (pledge("stdio rpath dns", NULL) == -1)
-                       err(1, "pledge");
-       } else {
-               if (pledge("stdio rpath dns", NULL) == -1)
-                       err(1, "pledge");
-       }
-
-       switch (kw) {
        case K_GET:
                uid = 0;
                /* FALLTHROUGH */
@@ -330,7 +319,7 @@ flushroutes(int argc, char **argv)
        }

        if (nflag) {
-               if (pledge("stdio rpath dns", NULL) == -1)
+               if (pledge("stdio", NULL) == -1)
                        err(1, "pledge");
        } else {
                if (pledge("stdio rpath dns", NULL) == -1)
@@ -445,6 +434,9 @@ newroute(int argc, char **argv)
        int key;
        uint8_t prio = 0;
        struct hostent *hp = NULL;
+
+       if (pledge("stdio rpath dns", NULL) == -1)
+               err(1, "pledge");

        if (uid)
                errx(1, "must be root to alter routing table");
Index: show.c
===================================================================
RCS file: /cvs/src/sbin/route/show.c,v
retrieving revision 1.102
diff -u -p -u -r1.102 show.c
--- show.c      23 Oct 2015 15:03:25 -0000      1.102
+++ show.c      15 Nov 2015 18:06:09 -0000
@@ -146,7 +146,7 @@ p_rttables(int af, u_int tableid, int ha
        }

        if (nflag) {
-               if (pledge("stdio rpath dns", NULL) == -1)
+               if (pledge("stdio", NULL) == -1)
                        err(1, "pledge");
        } else {
                if (pledge("stdio rpath dns", NULL) == -1)

On 13/11/2015 19:08, Sebastian Benoit wrote:
> Ricardo Mestre([email protected]) on 2015.11.13 18:00:11 +0000:
>> Hello,
>>
>> If '-n' argument is used on route(8) then nflag will be active and dns
>> transactions won't be needed, am I correct?
> 
> please find out yourself.
> 
> at least the pledge call in monitor will fail with -n and your diff,
> so some more work is required.
> 
>> Index: route.c
>> ===================================================================
>> RCS file: /cvs/src/sbin/route/route.c,v
>> retrieving revision 1.179
>> diff -u -p -u -r1.179 route.c
>> --- route.c  25 Oct 2015 09:37:08 -0000      1.179
>> +++ route.c  13 Nov 2015 15:37:37 -0000
>> @@ -227,7 +227,7 @@ main(int argc, char **argv)
>>      }
>>              
>>      if (nflag) {
>> -            if (pledge("stdio rpath dns", NULL) == -1)
>> +            if (pledge("stdio rpath", NULL) == -1)
>>                      err(1, "pledge");
>>      } else {
>>              if (pledge("stdio rpath dns", NULL) == -1)
>> @@ -330,7 +330,7 @@ flushroutes(int argc, char **argv)
>>      }
>>  
>>      if (nflag) {
>> -            if (pledge("stdio rpath dns", NULL) == -1)
>> +            if (pledge("stdio rpath", NULL) == -1)
>>                      err(1, "pledge");
>>      } else {
>>              if (pledge("stdio rpath dns", NULL) == -1)
>> Index: show.c
>> ===================================================================
>> RCS file: /cvs/src/sbin/route/show.c,v
>> retrieving revision 1.102
>> diff -u -p -u -r1.102 show.c
>> --- show.c   23 Oct 2015 15:03:25 -0000      1.102
>> +++ show.c   13 Nov 2015 15:37:37 -0000
>> @@ -146,7 +146,7 @@ p_rttables(int af, u_int tableid, int ha
>>      }
>>  
>>      if (nflag) {
>> -            if (pledge("stdio rpath dns", NULL) == -1)
>> +            if (pledge("stdio rpath", NULL) == -1)
>>                      err(1, "pledge");
>>      } else {
>>              if (pledge("stdio rpath dns", NULL) == -1)
>>
>> Best regards,
>> Ricardo Mestre
>>
> 

Reply via email to