Your message dated Wed, 11 Apr 2007 18:57:08 +0200
with message-id <[EMAIL PROTECTED]>
and subject line Bug#417605: asmail.c overwrites errno before looking at it
has caused the attached Bug report to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere. Please contact me immediately.)
Debian bug tracking system administrator
(administrator, Debian Bugs database)
--- Begin Message ---
Package: asmail
Version: 2.0-1
Severity: normal
Tags: patch
The asmail.c file from the asmail source distribution
repeatedly contains the following two lines:
printf(<some custom error message);
perror("asmail: <routine name>");
For instance, as
if ( ! tmp_pixfile ) {
printf("asmail: parse_cfg_animate: failed to allocate memory
for the pixfile\n");
perror("asmail: parse_cfg_animate: ");
return(-1);
}
on line 262. This is wrong, because the printf may cause
errno to be set to a value different from the one
corresponding w/ the original failure, causing the
perror to print a wrong message. An especially nasty
variant of this is on lines 670 - 681:
if ( stat(filename, &f_stat) ) {
printf("asmail: Cannot stat the config file (%s).\n", filename);
/* if the file does not exist, we still can run with
* the default settings using $MAIL unless a config
* file was given on command line. */
if ( ! flag_config_specified )
if ( ENOENT == errno )
return(-2);
perror("asmail: parse_cfg");
return(-1);
}
The intent is to treat a missing configuration file
as non-fatal error, ie to print a warning and to continue
processing after that. If the stat fails because
the configuration file does not exist and stdout is
redirected to /dev/null, an ioctl done internally as
part of the printf-processing causes errno to be
set to ENOTTY before the nested if below the printf
tests for errno == ENOENT. The program then terminates
itself because of the 'unexpected' error.
A patch that fixes this:
diff -rNu asmail-2.0.orig/asmail.c asmail-2.0/asmail.c
--- asmail-2.0.orig/asmail.c 2007-04-03 18:04:15.000000000 +0200
+++ asmail-2.0/asmail.c 2007-04-03 18:39:54.000000000 +0200
@@ -6,6 +6,7 @@
* This software is distributed under GPL. For details see LICENSE file.
*/
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -52,6 +53,19 @@
printf("\n");
}
+static void err_printf(char const *tmpl, ...) {
+ va_list val;
+ int errno_;
+
+ errno_ = errno;
+
+ va_start(val, tmpl);
+ vprintf(tmpl, val);
+ va_end(val);
+
+ errno = errno_;
+}
+
/*
* Set up the defaults that cannot be determined at compile time.
*/
@@ -260,7 +274,7 @@
tmp_pixfile = (struct pixfile *)
malloc(sizeof(struct pixfile));
if ( ! tmp_pixfile ) {
- printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
+ err_printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
perror("asmail: parse_cfg_animate: ");
return(-1);
}
@@ -273,7 +287,7 @@
tmp_pixfile = (struct pixfile *)
malloc(sizeof(struct pixfile));
if ( ! tmp_pixfile ) {
- printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
+ err_printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
perror("asmail: parse_cfg_animate: ");
return(-1);
}
@@ -286,7 +300,7 @@
tmp_pixfile = (struct pixfile *)
malloc(sizeof(struct pixfile));
if ( ! tmp_pixfile ) {
- printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
+ err_printf("asmail: parse_cfg_animate:
failed to allocate memory for the pixfile\n");
perror("asmail: parse_cfg_animate: ");
return(-1);
}
@@ -302,7 +316,7 @@
tmp_pixfile = (struct pixfile *)
malloc(sizeof(struct pixfile));
if ( ! tmp_pixfile ) {
- printf("asmail:
parse_cfg_animate: failed to allocate memory for the pixfile\n");
+ err_printf("asmail:
parse_cfg_animate: failed to allocate memory for the pixfile\n");
perror("asmail:
parse_cfg_animate: ");
return(-1);
}
@@ -668,7 +682,7 @@
char rest[MAX_INPUT_LENGTH+1];
if ( stat(filename, &f_stat) ) {
- printf("asmail: Cannot stat the config file (%s).\n", filename);
+ err_printf("asmail: Cannot stat the config file (%s).\n",
filename);
/* if the file does not exist, we still can run with
* the default settings using $MAIL unless a config
* file was given on command line. */
@@ -679,7 +693,7 @@
return(-1);
}
if ( ( f = fopen(filename, "r") ) == NULL ) {
- printf("asmail: Cannot open the config file (%s).\n", filename);
+ err_printf("asmail: Cannot open the config file (%s).\n",
filename);
perror("asmail: parse_cfg");
return(-1);
}
@@ -719,7 +733,7 @@
}
if ( fclose(f) ) {
- printf("asmail: Cannot close the config file (%s).\n",
filename);
+ err_printf("asmail: Cannot close the config file (%s).\n",
filename);
perror("asmail: parse_cfg");
return(-1);
}
--- End Message ---
--- Begin Message ---
Albert 'Tigr' Dorofeev wrote:
> Hi!
>
> The patch kindly supplied by Rainer was applied
> to the asmail in version 2.1. Please, update the
> distribution with the latest version
> (http://www.tigr.net/afterstep/download/asmail/asmail-2.1.tar.gz)
>
> My great thanks to Rainer for spotting the problem
> that is, indeed, a grave one. I am happy that such
> a serious error was corrected. Thanks again!
Ok asmail_2.1-1 is uploaded which closes this bug.
--- End Message ---