segmentation fault

Michel de Boer <[email protected]>
Newsgroups gmane.comp.gnu.ccrtp.devel
Message-ID <[email protected]>
Hi David, Federico,

I have been debugging a segmentation fault that only happened on
one machine. After a lot of debugging I found the cause. The
backtrace I get is:

#7  0x41161903 in strlen () from /lib/tls/libc.so.6
#8  0x401b59eb in ost::RTPApplication::findCNAME (this=0x0)
     at char_traits.h:143
#9  0x401b5c49 in RTPApplication (this=0x401c9d80, cname=@0xbfffe2a0)
     at source.cpp:161
#10 0x401b5d16 in ost::defaultApplication () at stl_alloc.h:652
#11 0x081ad0dc in t_twinkle_rtp_session (this=0x84bb668, host=@0x0,
     port=5004) at twinkle_rtp_session.cpp:6
#12 0x081a0b1f in t_audio_session (this=0x83acd10, _session=0x84ae35c,
     _recv_host=@0x82290e8, _recv_port=5004, _dst_host=@0x845d018,
     _dst_port=12668, _codec=139125596, _ptime=20) at basic_string.h:716

I found that this crash can happen for 2 reasons:

1) LOGNAME is not set
2) The hostname is not in /etc/hosts

In both cases ccrtp tries to use a NULL pointer.

Attached you find a patch that fixes the problem. I hope you will fix
this in the next release.

Best regards,
Michel

_______________________________________________
Ccrtp-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/ccrtp-devel
source.patch (text/x-patch, 947 B)
--- ccrtp-1.3.5/src/source.cpp	2005-01-24 16:14:55.000000000 +0100
+++ ccrtp-1.3.5-patched/src/source.cpp	2005-11-26 18:05:11.000000000 +0100
@@ -76,7 +76,7 @@
 	//    customization of the environment.
 	// Try both LOGNAME and USER env. var.
 	const char *user = Process::getEnv("LOGNAME");
-	if ( !strcmp(user,"") )
+	if ( !user || !strcmp(user,"") )
 		user = Process::getEnv("USER");
 	if ( user )
 		username = user;
@@ -231,9 +231,18 @@
 	// build string username@host_fqn
 	std::string username;
 	findusername(username);
-	
+	 
+	// First create an InetHostAddress object, otherwise the
+	// object will be destructed and the hostname corrupted.
+	InetHostAddress iha;
+	const char *p = iha.getHostname();
+
+	// Returned hostname can be NULL
+	std::string hname;
+	if (p) hname = p;
+
 	setSDESItem(SDESItemTypeCNAME, 
-		    username + "@" + InetHostAddress().getHostname());
+		    username + "@" + hname);
 }
 
 #ifdef	CCXX_NAMESPACES
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.