Skip to contentSkip to conversation

SIGSEGV in resolving hostname

PATCH Benoit DOLEZ 1 participant 1 message Oct 22, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

When there is not reverse for the hostname, the gethostbyname return NULL. There is no check of the return value in the function hostnamestr() (strgen:144). Because of the SIGSEGV generated, the normal might not working.

Here you can find a patch, the hostname is used in the HELO part. It might be interesting to specify the hostname in the config, for the moment, I had a patch that use the non reversed hostname if the hostnamestr return NULL.

Under Slakware, the hostname command return the first part of the FQDN hostname.

Benoit

Signature · 2 lines
Benoit DOLEZ
GSM: +33 6 21 05 91 69                mailto:[email protected]
src/mlmmj-send.c +13 -1
diff -r -u mlmmj-1.2.12-RC4/src/mlmmj-send.c mlmmj-1.2.12-RC4-flx0.1/src/mlmmj-send.c
@@ -326,7 +326,19 @@
 	int retval = 0;
 	char *reply = NULL;
 	char *myhostname = hostnamestr();
-	
+
+        if (!myhostname) {
+              char tmp[256];
+              if (gethostname(tmp, 256) != 0) {
+                   perror("FATAL: gethostname()");
+                   exit(1);
+              }
+              if (!(myhostname = mystrdup(tmp))) {
+                   perror("FATAL: mystrdup()");
+                   exit(1);
+              }
+        }      
+
 	init_sockfd(sockfd, relayhost, port);
 	
 	if((reply = checkwait_smtpreply(*sockfd, MLMMJ_CONNECT)) != NULL) {
src/strgen.c +1 -1
diff -r -u mlmmj-1.2.12-RC4/src/strgen.c mlmmj-1.2.12-RC4-flx0.1/src/strgen.c
@@ -144,7 +144,7 @@
         hostname[sizeof(hostname)-1] = '\0';
         hostlookup = gethostbyname(hostname);
 
-        return mystrdup(hostlookup->h_name);
+        return (hostlookup ? mystrdup(hostlookup->h_name) : NULL);
 }
 
 char *mydirname(const char *path)