]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
l_net: don't segfault of gethostbyname(gethostname()) fails
authorRudolf Polzer <divverent@xonotic.org>
Wed, 24 Oct 2012 13:55:42 +0000 (15:55 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Wed, 24 Oct 2012 13:55:42 +0000 (15:55 +0200)
Can happen on Linux with misconfigured /etc/hosts.

libs/l_net/l_net_berkley.c
libs/l_net/l_net_wins.c

index 7e5a50e0045310caa3a4417238e701b33e7e33c2..020592568835a02be4382dce394d20b9288b97ff 100644 (file)
@@ -173,7 +173,10 @@ int WINS_Init( void ){
        // determine my name & address
        gethostname( buff, MAXHOSTNAMELEN );
        local = gethostbyname( buff );
-       myAddr = *(int *)local->h_addr_list[0];
+       if(local && local->h_addr_list && local->h_addr_list[0])
+               myAddr = *(int *)local->h_addr_list[0];
+       else
+               myAddr = inet_ntoa("127.0.0.1");
 
        // if the quake hostname isn't set, set it to the machine name
 //     if (Q_strcmp(hostname.string, "UNNAMED") == 0)
index ca888259530f225422dcf7a9a57108ea0bd9e2f7..c56b17ed4f584ceab6f32b7957ffcecf451e8f8f 100644 (file)
@@ -196,7 +196,10 @@ int WINS_Init( void ){
        // determine my name & address
        gethostname( buff, MAXHOSTNAMELEN );
        local = gethostbyname( buff );
-       myAddr = *(int *)local->h_addr_list[0];
+       if(local && local->h_addr_list && local->h_addr_list[0])
+               myAddr = *(int *)local->h_addr_list[0];
+       else
+               myAddr = inet_ntoa("127.0.0.1");
 
        // if the quake hostname isn't set, set it to the machine name
 //     if (Q_strcmp(hostname.string, "UNNAMED") == 0)