ufms.c
2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ufms.c - a test of "UNIX mailbox first message symptom"
Copyright (C) 2010-2012, 2014 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <mailutils/mailutils.h>
/* UFMS, or "UNIX mailbox first message symptom", is a bug that
existed in all versions of Mailutils up to 2.2.1 and 2.9.90
as of 2010-11-07.
Due to improperly designed expunge routine, the body of the very
first message in a UNIX mailbox would get corrupted under certain
circumstances. The following three lines would appear at the top
of the body:
-IMAPbase: X Y
Status: S
X-UID: Z
where (X, Y, Z are decimal numbers and S is a status string).
Prerequisites for triggering the bug:
1. Mailbox contains more than one message.
2. The first message does not carry X-IMAPbase and X-UID headers.
Recipe for triggering the bug:
1. Delete some messages.
2. Expunge the mailbox.
3. Modify attributes of the first message.
4. Flush your changes.
*/
int
main (int argc, char **argv)
{
mu_mailbox_t mbox;
size_t i, count;
mu_message_t msg;
mu_attribute_t attr;
if (argc != 2)
{
fprintf (stderr, "usage: %s MBOX\n", argv[0]);
return 1;
}
mu_registrar_record (mu_mbox_record);
/* Open the mailbox */
MU_ASSERT (mu_mailbox_create (&mbox, argv[1]));
MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_RDWR));
mu_mailbox_messages_count (mbox, &count);
if (count < 2)
{
fprintf (stderr,
"%s: input mailbox should contain at least two messages\n",
argv[0]);
exit (1);
}
/* Delete all records except the first and expunge the mailbox. */
for (i = 2; i <= count; i++)
{
MU_ASSERT (mu_mailbox_get_message (mbox, i, &msg));
MU_ASSERT (mu_message_get_attribute (msg, &attr));
MU_ASSERT (mu_attribute_set_deleted (attr));
}
mu_mailbox_expunge (mbox);
/* Modify attributes on the remaining message and synch */
MU_ASSERT (mu_mailbox_get_message (mbox, 1, &msg));
MU_ASSERT (mu_message_get_attribute (msg, &attr));
MU_ASSERT (mu_attribute_set_read (attr));
mu_mailbox_sync (mbox);
/* Cleanup & exit */
mu_mailbox_close (mbox);
mu_mailbox_destroy (&mbox);
return 0;
}