Date: Fri, 4 Jan 2002 05:30:02 -0800 (PST) From: Kimura Fuyuki <fuyuki@mj.0038.net> To: freebsd-ports@FreeBSD.org Subject: Re: ports/32899: mail/nbsmtp causes segfaults while a command line parsing Message-ID: <200201041330.g04DU2h39650@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR ports/32899; it has been noted by GNATS. From: Kimura Fuyuki <fuyuki@mj.0038.net> To: ppl@nbnet.nb.ca Cc: freebsd-gnats-submit@FreeBSD.org Subject: Re: ports/32899: mail/nbsmtp causes segfaults while a command line parsing Date: Fri, 04 Jan 2002 22:29:12 +0900 > 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) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200201041330.g04DU2h39650>