miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

testgetifaddr.sh doesn't handle missing default route

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpd Bugs
View previous topic :: View next topic  
Author Message
mgorny



Joined: 03 Oct 2019
Posts: 6

PostPosted: Sun Aug 22, 2021 7:40 am    Post subject: testgetifaddr.sh doesn't handle missing default route Reply with quote

Hi,

We're running the miniupnpd test suite in an isolated environment without external network access. However, it seems that testgetifaddr.sh relies on the default route to get interface name.

The output is:

Code:
/bin/sh testgetifaddr.sh                                                                                                               
Usage:  ./testgetifaddr interface_name
testgetifaddr test FAILED : 127.0.0.1                                                                                                 
10.0.0.1 !=                                                                                                                           
make: *** [check.mk:12: validategetifaddr] Error 1


Firstly, there's a mistake in error handling when getting EXTIF:

Code:
EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1


This exit will only happen if the last command on the pipeline (i.e. sed) fails which doesn't happen. On my system, grep returns unsucessfully (because it can't find default) but sed clobbers that exit code. If the intention is to exit when you can't get the default route, you probably need to split this into more variables and check exit status from grep.

However, I think we can resolve the problem without causing any regressions by grabbing the interface name from 'ip addr show' output, i.e. doing something like (added the middle line):

Code:
   EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1
   EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2 }' | cut -d ":" -f 1`"
   EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2 }' | cut -d "/" -f 1`"


This will still prefer using the interface with the default route but will accept any interface returned by 'ip -4 addr show'.
Back to top
View user's profile Send private message
mgorny



Joined: 03 Oct 2019
Posts: 6

PostPosted: Sun Aug 22, 2021 7:47 am    Post subject: Reply with quote

Hmm, it seems that you also need to terminate the awk after getting first IP address, as otherwise the test will fail if the interface has multiple addresses.

I'm going to submit a PR.
Back to top
View user's profile Send private message
mgorny



Joined: 03 Oct 2019
Posts: 6

PostPosted: Sun Aug 22, 2021 8:01 am    Post subject: Reply with quote

https://github.com/miniupnp/miniupnp/pull/563
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Sun Aug 22, 2021 10:59 pm    Post subject: Reply with quote

thank you !
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
mgorny



Joined: 03 Oct 2019
Posts: 6

PostPosted: Mon Aug 23, 2021 6:25 am    Post subject: Reply with quote

Thanks for maintaining miniupnp* ;-).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpd Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.