Hi again, I wrote: > [...] which fixes this incompatibility. ... but that's "which should have fixed"
I'm really sorry for the first fix, which is really bad. I hope that this one is better. It allocates memory dynamically and makes the previous-used "buffer" useless, at least in the file "original.c". If the upstream is OK with that patch, I'd like to suggest being precautious when using the domain field. At first glance, there are 3 occurrences of it used in "nbsmtp.c", in asprintf() functions. I might write a patch if upstream wants me to. Cheers, -- Cyril Brulebois
--- nbsmtp-1.00/original.c.orig 2006-07-27 10:11:12.000000000 +0000 +++ nbsmtp-1.00/original.c 2006-07-27 10:11:16.000000000 +0000 @@ -54,7 +54,6 @@ int parse_options(int argc,char *argv[], servinfo_t *serverinfo) { int c; - char buffer[BUF_SIZE]; bool_t read_syswide = True; bool_t read_localconf = True; @@ -184,25 +183,57 @@ /* If domain isn't specified, use machines hostname */ if (serverinfo->domain==NULL) { - if (gethostname(buffer,MAXHOSTNAMELEN)==-1) + /* As a quick reminder: According to POSIX, MAXHOSTNAMELEN can be + * undefined, thus using a tiny loop around 'gethostname', beginning + * with a buffer size equal to a common MAXHOSTNAMELEN value + * (but it's an arbitrary value). + */ + int domain_size=64; + + serverinfo->domain = malloc(domain_size); + if (!(serverinfo->domain)) { - perror("gethostname"); + perror("domain malloc"); return 1; } - else + + while (gethostname(serverinfo->domain, domain_size)==-1) { - serverinfo->domain = (char *)strdup(buffer); + if (errno==ENAMETOOLONG) + { + domain_size *= 2; + serverinfo->domain = realloc(serverinfo->domain, domain_size); + if (!(serverinfo->domain)) + { + perror("gethostname: domain realloc"); + return 1; + } + } + else + { + perror("gethostname"); + return 1; + } } } /* If from address isn't specified, build up one */ if (serverinfo->fromaddr==NULL) { + /* Please have a look at the quick reminder above, what + * follows (dynamic allocation) is a direct consequence. + */ struct passwd *user = getpwuid(getuid()); + int fromaddr_len = strlen(user->pw_name) + strlen(serverinfo->domain) + 2; - snprintf(buffer,sizeof(buffer),"[EMAIL PROTECTED]",user->pw_name,serverinfo->domain,'\0'); + serverinfo->fromaddr = malloc(fromaddr_len); + if (!(serverinfo->fromaddr)) + { + perror("fromaddr malloc"); + return 1; + } - serverinfo->fromaddr = (char *)strdup(buffer); + snprintf(serverinfo->fromaddr,fromaddr_len,"[EMAIL PROTECTED]",user->pw_name,serverinfo->domain,'\0'); } /* If we haven't enough info, print_usage and exit */