Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Dec 2001 14:10:01 -0800 (PST)
From:      Pierre-Paul Lavoie <ppl@nbnet.nb.ca>
To:        freebsd-ports@FreeBSD.org
Subject:   Re: ports/32899: mail/nbsmtp causes segfaults while a command line parsing
Message-ID:  <200112302210.fBUMA1N38100@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: Pierre-Paul Lavoie <ppl@nbnet.nb.ca>
To: freebsd-gnats-submit@FreeBSD.org, fuyuki@mj.0038.net
Cc:  
Subject: Re: ports/32899: mail/nbsmtp causes segfaults while a command line parsing
Date: Sun, 30 Dec 2001 18:08:11 -0400

 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)

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?200112302210.fBUMA1N38100>