HCoop
/
bpt
/
emacs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix part 4 of bug#9771 with assertion violation when wrap-prefix is used
[bpt/emacs.git]
/
lib-src
/
movemail.c
diff --git
a/lib-src/movemail.c
b/lib-src/movemail.c
index
b127c85
..
b6ea51f
100644
(file)
--- a/
lib-src/movemail.c
+++ b/
lib-src/movemail.c
@@
-1,7
+1,8
@@
/* movemail foo bar -- move file foo to file bar,
locking file foo the way /bin/mail respects.
/* movemail foo bar -- move file foo to file bar,
locking file foo the way /bin/mail respects.
- Copyright (C) 1986, 1992, 1993, 1994, 1996, 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+
+Copyright (C) 1986, 1992-1994, 1996, 1999, 2001-2011
+ Free Software Foundation, Inc.
This file is part of GNU Emacs.
This file is part of GNU Emacs.
@@
-67,9
+68,7
@@
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
-#endif
#include "syswait.h"
#ifdef MAIL_USE_POP
#include "pop.h"
#include "syswait.h"
#ifdef MAIL_USE_POP
#include "pop.h"
@@
-79,13
+78,6
@@
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#undef access
#endif /* MSDOS */
#undef access
#endif /* MSDOS */
-#ifndef DIRECTORY_SEP
-#define DIRECTORY_SEP '/'
-#endif
-#ifndef IS_DIRECTORY_SEP
-#define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
-#endif
-
#ifdef WINDOWSNT
#include "ntlib.h"
#undef access
#ifdef WINDOWSNT
#include "ntlib.h"
#undef access
@@
-137,7
+129,7
@@
extern int lk_open (), lk_close ();
files appear in. */
#ifdef MAILDIR
#define MAIL_USE_MAILLOCK
files appear in. */
#ifdef MAILDIR
#define MAIL_USE_MAILLOCK
-static char *mail_spool_name ();
+static char *mail_spool_name (
char *
);
#endif
#endif
#endif
#endif
@@
-160,7
+152,7
@@
static int mbx_delimit_end (FILE *mbf);
#endif
/* Nonzero means this is name of a lock file to delete on fatal error. */
#endif
/* Nonzero means this is name of a lock file to delete on fatal error. */
-char *delete_lockname;
+
static
char *delete_lockname;
int
main (int argc, char **argv)
int
main (int argc, char **argv)
@@
-168,15
+160,15
@@
main (int argc, char **argv)
char *inname, *outname;
int indesc, outdesc;
ssize_t nread;
char *inname, *outname;
int indesc, outdesc;
ssize_t nread;
- int status;
+ int
wait_
status;
int c, preserve_mail = 0;
#ifndef MAIL_USE_SYSTEM_LOCK
struct stat st;
int c, preserve_mail = 0;
#ifndef MAIL_USE_SYSTEM_LOCK
struct stat st;
- long now;
int tem;
int tem;
- char *lockname
, *p
;
+ char *lockname;
char *tempname;
char *tempname;
+ size_t inname_dirlen;
int desc;
#endif /* not MAIL_USE_SYSTEM_LOCK */
int desc;
#endif /* not MAIL_USE_SYSTEM_LOCK */
@@
-191,8
+183,8
@@
main (int argc, char **argv)
# define ARGSTR "p"
#endif /* MAIL_USE_POP */
# define ARGSTR "p"
#endif /* MAIL_USE_POP */
- uid_t real_gid = getgid();
- uid_t priv_gid = getegid();
+ uid_t real_gid = getgid
();
+ uid_t priv_gid = getegid
();
#ifdef WINDOWSNT
/* Ensure all file i/o is in binary mode. */
#ifdef WINDOWSNT
/* Ensure all file i/o is in binary mode. */
@@
-265,9
+257,22
@@
main (int argc, char **argv)
#ifndef MAIL_USE_SYSTEM_LOCK
#ifdef MAIL_USE_MAILLOCK
spool_name = mail_spool_name (inname);
#ifndef MAIL_USE_SYSTEM_LOCK
#ifdef MAIL_USE_MAILLOCK
spool_name = mail_spool_name (inname);
- if (! spool_name)
+ if (spool_name)
+ {
+#ifdef lint
+ lockname = 0;
+#endif
+ }
+ else
#endif
{
#endif
{
+ #ifndef DIRECTORY_SEP
+ #define DIRECTORY_SEP '/'
+ #endif
+ #ifndef IS_DIRECTORY_SEP
+ #define IS_DIRECTORY_SEP(_c_) ((_c_) == DIRECTORY_SEP)
+ #endif
+
/* Use a lock file named after our first argument with .lock appended:
If it exists, the mail file is locked. */
/* Note: this locking mechanism is *required* by the mailer
/* Use a lock file named after our first argument with .lock appended:
If it exists, the mail file is locked. */
/* Note: this locking mechanism is *required* by the mailer
@@
-292,27
+297,38
@@
main (int argc, char **argv)
to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
lockname = concat (inname, ".lock", "");
to bug-gnu-emacs@prep.ai.mit.edu so we can fix it. */
lockname = concat (inname, ".lock", "");
- tempname = (char *) xmalloc (strlen (inname) + strlen ("EXXXXXX") + 1);
- strcpy (tempname, inname);
- p = tempname + strlen (tempname);
- while (p != tempname && !IS_DIRECTORY_SEP (p[-1]))
- p--;
- *p = 0;
- strcpy (p, "EXXXXXX");
- mktemp (tempname);
- unlink (tempname);
+ for (inname_dirlen = strlen (inname);
+ inname_dirlen && !IS_DIRECTORY_SEP (inname[inname_dirlen - 1]);
+ inname_dirlen--)
+ continue;
+ tempname = (char *) xmalloc (inname_dirlen + sizeof "EXXXXXX");
while (1)
{
/* Create the lock file, but not under the lock file name. */
/* Give up if cannot do that. */
while (1)
{
/* Create the lock file, but not under the lock file name. */
/* Give up if cannot do that. */
- desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0666);
+
+ memcpy (tempname, inname, inname_dirlen);
+ strcpy (tempname + inname_dirlen, "EXXXXXX");
+#ifdef HAVE_MKSTEMP
+ desc = mkstemp (tempname);
+#else
+ mktemp (tempname);
+ if (!*tempname)
+ desc = -1;
+ else
+ {
+ unlink (tempname);
+ desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600);
+ }
+#endif
if (desc < 0)
{
if (desc < 0)
{
- char *message = (char *) xmalloc (strlen (tempname) + 50);
- sprintf (message, "creating %s, which would become the lock file",
- tempname);
- pfatal_with_name (message);
+ int mkstemp_errno = errno;
+ error ("error while creating what would become the lock file",
+ 0, 0);
+ errno = mkstemp_errno;
+ pfatal_with_name (tempname);
}
close (desc);
}
close (desc);
@@
-335,7
+351,7
@@
main (int argc, char **argv)
by time differences between machines. */
if (stat (lockname, &st) >= 0)
{
by time differences between machines. */
if (stat (lockname, &st) >= 0)
{
- now = time (0);
+
time_t
now = time (0);
if (st.st_ctime < now - 300)
unlink (lockname);
}
if (st.st_ctime < now - 300)
unlink (lockname);
}
@@
-351,10
+367,13
@@
main (int argc, char **argv)
int lockcount = 0;
int status = 0;
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
int lockcount = 0;
int status = 0;
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
- time_t touched_lock, now;
+ time_t touched_lock;
+# ifdef lint
+ touched_lock = 0;
+# endif
#endif
#endif
- if (setuid (getuid ()) < 0 || set
egid (
real_gid) < 0)
+ if (setuid (getuid ()) < 0 || set
regid (-1,
real_gid) < 0)
fatal ("Failed to drop privileges", 0, 0);
#ifndef MAIL_USE_MMDF
fatal ("Failed to drop privileges", 0, 0);
#ifndef MAIL_USE_MMDF
@@
-381,7
+400,7
@@
main (int argc, char **argv)
if (outdesc < 0)
pfatal_with_name (outname);
if (outdesc < 0)
pfatal_with_name (outname);
- if (set
egid (
priv_gid) < 0)
+ if (set
regid (-1,
priv_gid) < 0)
fatal ("Failed to regain privileges", 0, 0);
/* This label exists so we can retry locking
fatal ("Failed to regain privileges", 0, 0);
/* This label exists so we can retry locking
@@
-461,7
+480,7
@@
main (int argc, char **argv)
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
if (spool_name)
{
#if defined (MAIL_USE_MAILLOCK) && defined (HAVE_TOUCHLOCK)
if (spool_name)
{
- now = time (0);
+
time_t
now = time (0);
if (now - touched_lock > 60)
{
touchlock ();
if (now - touched_lock > 60)
{
touchlock ();
@@
-478,7
+497,7
@@
main (int argc, char **argv)
#endif
/* Prevent symlink attacks truncating other users' mailboxes */
#endif
/* Prevent symlink attacks truncating other users' mailboxes */
- if (set
egid (
real_gid) < 0)
+ if (set
regid (-1,
real_gid) < 0)
fatal ("Failed to drop privileges", 0, 0);
/* Check to make sure no errors before we zap the inbox. */
fatal ("Failed to drop privileges", 0, 0);
/* Check to make sure no errors before we zap the inbox. */
@@
-488,7
+507,8
@@
main (int argc, char **argv)
#ifdef MAIL_USE_SYSTEM_LOCK
if (! preserve_mail)
{
#ifdef MAIL_USE_SYSTEM_LOCK
if (! preserve_mail)
{
- ftruncate (indesc, 0L);
+ if (ftruncate (indesc, 0L) != 0)
+ pfatal_with_name (inname);
}
#endif /* MAIL_USE_SYSTEM_LOCK */
}
#endif /* MAIL_USE_SYSTEM_LOCK */
@@
-513,7
+533,7
@@
main (int argc, char **argv)
#endif /* not MAIL_USE_SYSTEM_LOCK */
/* End of mailbox truncation */
#endif /* not MAIL_USE_SYSTEM_LOCK */
/* End of mailbox truncation */
- if (set
egid (
priv_gid) < 0)
+ if (set
regid (-1,
priv_gid) < 0)
fatal ("Failed to regain privileges", 0, 0);
#ifdef MAIL_USE_MAILLOCK
fatal ("Failed to regain privileges", 0, 0);
#ifdef MAIL_USE_MAILLOCK
@@
-525,11
+545,11
@@
main (int argc, char **argv)
exit (EXIT_SUCCESS);
}
exit (EXIT_SUCCESS);
}
- wait (&status);
- if (!WIFEXITED (status))
+ wait (&
wait_
status);
+ if (!WIFEXITED (
wait_
status))
exit (EXIT_FAILURE);
exit (EXIT_FAILURE);
- else if (WRETCODE (status) != 0)
- exit (WRETCODE (status));
+ else if (WRETCODE (
wait_
status) != 0)
+ exit (WRETCODE (
wait_
status));
#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
#ifdef MAIL_USE_MAILLOCK
#if !defined (MAIL_USE_MMDF) && !defined (MAIL_USE_SYSTEM_LOCK)
#ifdef MAIL_USE_MAILLOCK
@@
-668,14
+688,8
@@
xmalloc (unsigned int size)
#define NOTOK (-1)
#define OK 0
#define NOTOK (-1)
#define OK 0
-#define DONE 1
-
-char *progname;
-FILE *sfi;
-FILE *sfo;
-char ibuffer[BUFSIZ];
-char obuffer[BUFSIZ];
-char Errmsg[200]; /* POP errors, at least, can exceed
+
+static char Errmsg[200]; /* POP errors, at least, can exceed
the original length of 80. */
/*
the original length of 80. */
/*
@@
-734,7
+748,18
@@
popmail (char *mailbox, char *outfile, int preserve, char *password, int reverse
error ("Error in open: %s, %s", strerror (errno), outfile);
return EXIT_FAILURE;
}
error ("Error in open: %s, %s", strerror (errno), outfile);
return EXIT_FAILURE;
}
- fchown (mbfi, getuid (), -1);
+
+ if (fchown (mbfi, getuid (), -1) != 0)
+ {
+ int fchown_errno = errno;
+ struct stat st;
+ if (fstat (mbfi, &st) != 0 || st.st_uid != getuid ())
+ {
+ pop_close (server);
+ error ("Error in fchown: %s, %s", strerror (fchown_errno), outfile);
+ return EXIT_FAILURE;
+ }
+ }
if ((mbf = fdopen (mbfi, "wb")) == NULL)
{
if ((mbf = fdopen (mbfi, "wb")) == NULL)
{
@@
-826,10
+851,10
@@
pop_retr (popserver server, int msgno, FILE *arg)
if (pop_retrieve_first (server, msgno, &line))
{
if (pop_retrieve_first (server, msgno, &line))
{
- char *
error
= concat ("Error from POP server: ", pop_error, "");
- strncpy (Errmsg,
error
, sizeof (Errmsg));
+ char *
msg
= concat ("Error from POP server: ", pop_error, "");
+ strncpy (Errmsg,
msg
, sizeof (Errmsg));
Errmsg[sizeof (Errmsg)-1] = '\0';
Errmsg[sizeof (Errmsg)-1] = '\0';
- free
(error
);
+ free
(msg
);
return (NOTOK);
}
return (NOTOK);
}
@@
-848,27
+873,26
@@
pop_retr (popserver server, int msgno, FILE *arg)
if (ret)
{
if (ret)
{
- char *
error
= concat ("Error from POP server: ", pop_error, "");
- strncpy (Errmsg,
error
, sizeof (Errmsg));
+ char *
msg
= concat ("Error from POP server: ", pop_error, "");
+ strncpy (Errmsg,
msg
, sizeof (Errmsg));
Errmsg[sizeof (Errmsg)-1] = '\0';
Errmsg[sizeof (Errmsg)-1] = '\0';
- free
(error
);
+ free
(msg
);
return (NOTOK);
}
return (OK);
}
return (NOTOK);
}
return (OK);
}
-/* Do this as a macro instead of using strcmp to save on execution time. */
-#define IS_FROM_LINE(a) ((a[0] == 'F') \
- && (a[1] == 'r') \
- && (a[2] == 'o') \
- && (a[3] == 'm') \
- && (a[4] == ' '))
-
static int
mbx_write (char *line, int len, FILE *mbf)
{
#ifdef MOVEMAIL_QUOTE_POP_FROM_LINES
static int
mbx_write (char *line, int len, FILE *mbf)
{
#ifdef MOVEMAIL_QUOTE_POP_FROM_LINES
+ /* Do this as a macro instead of using strcmp to save on execution time. */
+ # define IS_FROM_LINE(a) ((a[0] == 'F') \
+ && (a[1] == 'r') \
+ && (a[2] == 'o') \
+ && (a[3] == 'm') \
+ && (a[4] == ' '))
if (IS_FROM_LINE (line))
{
if (fputc ('>', mbf) == EOF)
if (IS_FROM_LINE (line))
{
if (fputc ('>', mbf) == EOF)