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
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)
> 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)
Responsible Changed From-To: freebsd-ports->anders Over to maintainer
State Changed From-To: open->feedback
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.
> 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...
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.
State Changed From-To: feedback->closed Committed, thanks!