Bug 32899

Summary: mail/nbsmtp causes segfaults while a command line parsing
Product: Ports & Packages Reporter: Kimura Fuyuki <fuyuki>
Component: Individual Port(s)Assignee: Anders Nordby <anders>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Kimura Fuyuki 2001-12-16 13:00:01 UTC
nbsmtp causes segfaults while a command line parsing because of the
bad pointer derefs .

Fix: 

Rewrite the command line parser, possibly using getopt(3).
How-To-Repeat: nbsmtp -h
Comment 1 Pierre-Paul Lavoie 2001-12-30 22:08:11 UTC
Here's a possible patch using getopt
-ppl

--- nbsmtp.cFri Apr  6 21:09:01 2001
+++ nbsmtp-patch.cSun Dec 30 12:05:03 2001
@@ -19,6 +19,8 @@
 */  #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -76,42 +78,46 @@
 {
   printf("Usage:\n");
   printf("%s -d domain -f from@addr -h host [-p port] [-l debuglevel]\n", prog);
+  exit(EXIT_FAILURE);
 }  int main(int argc, char *argv[])
 {
-  int i;
+  int ch; -  for(i=1; i<argc; i+=2){
-    switch(*(argv[i]+1))
+  while ( (ch = getopt(argc, argv, "h:d:f:p:l:")) != -1){
+    switch (ch)
       {
       case 'h':
-host = (char *)strdup(argv[i+1]);
+host = strdup(optarg);
 break;
       case 'd':
-domain = (char *)strdup(argv[i+1]);
+domain = strdup(optarg);
 break;
       case 'f':
-fromaddr = (char *)strdup(argv[i+1]);
+fromaddr = strdup(optarg);
 break;
       case 'p':
-port = atoi(argv[i+1]);
+port = atoi(optarg);
 break;
       case 'l':
-debug_level =  atoi(argv[i+1]);
+debug_level = atoi(optarg);
 if(debug_level > 1)
   stdlog = fopen("nbsmtp.log", "w");
 else
   stdlog = stdout;
 break;
+      case '?':
       default:
 print_usage(argv[0]);
+break;
       }
   }
+  argc -= optind;
+  argv += optind;    if(domain==NULL || fromaddr==NULL || host==NULL){
     print_usage(argv[0]);
-    return 1;
   }    if(port==0)
Comment 2 Kimura Fuyuki 2002-01-04 13:29:12 UTC
> Here's a possible patch using getopt

Your patch seems to be broken (copy/paste?), so I remade it, with one
fix :)

--- nbsmtp.c.orig	Sat Apr  7 09:09:01 2001
+++ nbsmtp.c	Fri Jan  4 22:20:55 2002
@@ -19,6 +19,8 @@
 */

 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -76,42 +78,45 @@
 {
   printf("Usage:\n");
   printf("%s -d domain -f from@addr -h host [-p port] [-l debuglevel]\n", prog);
+  exit(EXIT_FAILURE);
 }

 int main(int argc, char *argv[])
 {
-  int i;
+  int ch;

-  for(i=1; i<argc; i+=2){
-    switch(*(argv[i]+1))
+  while ( (ch = getopt(argc, argv, "h:d:f:p:l:")) != -1){
+    switch (ch)
       {
       case 'h':
-	host = (char *)strdup(argv[i+1]);
+	host = strdup(optarg);
 	break;
       case 'd':
-	domain = (char *)strdup(argv[i+1]);
+	domain = strdup(optarg);
 	break;
       case 'f':
-	fromaddr = (char *)strdup(argv[i+1]);
+	fromaddr = strdup(optarg);
 	break;
       case 'p':
-	port = atoi(argv[i+1]);
+	port = atoi(optarg);
 	break;
       case 'l':
-	debug_level =  atoi(argv[i+1]);
+	debug_level = atoi(optarg);
 	if(debug_level > 1)
 	  stdlog = fopen("nbsmtp.log", "w");
 	else
 	  stdlog = stdout;
 	break;
+      case '?':
       default:
 	print_usage(argv[0]);
+	break;
       }
   }

+  argc -= optind;
   if(domain==NULL || fromaddr==NULL || host==NULL){
     print_usage(argv[0]);
-    return 1;
   }

   if(port==0)
Comment 3 Pete Fritchman freebsd_committer freebsd_triage 2002-02-26 09:23:04 UTC
Responsible Changed
From-To: freebsd-ports->anders

Over to maintainer
Comment 4 Anders Nordby freebsd_committer freebsd_triage 2002-03-17 23:44:51 UTC
State Changed
From-To: open->feedback
Comment 5 anders 2002-03-17 23:54:42 UTC
Hello,

How about running these changes through the author of nbsmtp? It seems
he is looking for someone to take over the nbsmtp project. Any of you
interested in that?

Cc: to him. See http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/32899
for patches.

Cheers,

-- 
Anders.
Comment 6 Kimura Fuyuki 2002-03-18 01:02:50 UTC
> How about running these changes through the author of nbsmtp? It seems
> he is looking for someone to take over the nbsmtp project. Any of you
> interested in that?

I'm not using nbsmtp for now, though still looking for a simple MTA...
Comment 7 Pierre-Paul Lavoie 2002-03-18 17:57:17 UTC
I'm not using nbsmtp and I'm already involved in other open source
projects unfortunetly.

On Sun, 2002-03-17 at 19:54, Anders Nordby wrote:
> Hello,
> 
> How about running these changes through the author of nbsmtp? It seems
> he is looking for someone to take over the nbsmtp project. Any of you
> interested in that?
> 
> Cc: to him. See http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/32899
> for patches.
> 
> Cheers,
> 
> -- 
> Anders.
Comment 8 Anders Nordby freebsd_committer freebsd_triage 2002-04-10 21:21:03 UTC
State Changed
From-To: feedback->closed

Committed, thanks!