From cb907744d6cd176a2e27dbf120f8437ad27bf7f4 Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Wed, 24 Oct 2012 15:55:42 +0200 Subject: [PATCH] l_net: don't segfault of gethostbyname(gethostname()) fails Can happen on Linux with misconfigured /etc/hosts. --- libs/l_net/l_net_berkley.c | 5 ++++- libs/l_net/l_net_wins.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/l_net/l_net_berkley.c b/libs/l_net/l_net_berkley.c index 7e5a50e0..02059256 100644 --- a/libs/l_net/l_net_berkley.c +++ b/libs/l_net/l_net_berkley.c @@ -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) diff --git a/libs/l_net/l_net_wins.c b/libs/l_net/l_net_wins.c index ca888259..c56b17ed 100644 --- a/libs/l_net/l_net_wins.c +++ b/libs/l_net/l_net_wins.c @@ -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) -- 2.39.2