Summary:ASTERISK-04098: [patch] gethostname may return unterminated strings
Reporter:Luigi Rizzo (rizzo)Labels:
Date Opened:2005-05-06 15:52:58Date Closed:2008-01-15 15:34:42.000-0600
Versions:Frequency of
Environment:Attachments:( 0) gethostname.diff
Description:gethostname is used in some cases in a way that may returning the string without a trailing '\0'
The attached patch fixes the problem.
It also includes replacement of the magic constant 256 for the buffer size with MAXHOSTNAMELEN, which is suggested in FreeBSD. Not sure that the same is really portable, so perhaps this part of the patch could be left out.

There is also some unconsistency in the way a missing hostname is translated. Some instances replace it with "<Unknown>", some with "unknown", some with "localhost".
Comments:By: Olle Johansson (oej) 2005-05-06 16:07:14

Disclaimer on file?

By: Luigi Rizzo (rizzo) 2005-05-06 17:00:30

yes disclaimer on file.

By: Russell Bryant (russell) 2005-05-07 23:11:15

MAXHOSTNAMELEN appears to work fine on Linux

By: Olle Johansson (oej) 2005-05-08 05:30:46

Added similar patch to chan_sip.c in ASTERISK-4112

By: Mark Spencer (markster) 2005-05-08 12:38:48

Added to CVS with modifications.  It's important that non-global variables actually be initialized to "" to make sure that the termination actually takes place.

By: Russell Bryant (russell) 2005-05-15 11:50:26

fixed in 1.0 as well

By: Digium Subversion (svnbot) 2008-01-15 15:33:38.000-0600

Repository: asterisk
Revision: 5600

U   trunk/acl.c
U   trunk/apps/app_voicemail.c
U   trunk/asterisk.c
U   trunk/channels/chan_mgcp.c
U   trunk/logger.c
U   trunk/pbx/pbx_dundi.c

r5600 | markster | 2008-01-15 15:33:37 -0600 (Tue, 15 Jan 2008) | 2 lines

Fix gethostname calls (bug ASTERISK-4098, with mods)



By: Digium Subversion (svnbot) 2008-01-15 15:34:42.000-0600

Repository: asterisk
Revision: 5675

U   branches/v1-0/acl.c
U   branches/v1-0/apps/app_voicemail.c
U   branches/v1-0/asterisk.c
U   branches/v1-0/channels/chan_mgcp.c
U   branches/v1-0/channels/chan_sip.c
U   branches/v1-0/logger.c
U   branches/v1-0/res/res_features.c

r5675 | russell | 2008-01-15 15:34:42 -0600 (Tue, 15 Jan 2008) | 3 lines

ensure that calls to gethostbyname are null terminated,
also use MAXHOSTNAMELEN where appropriate (bug ASTERISK-4098) (bug ASTERISK-4112)