[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-list.c,1.4,1.5 mbox-save.c,1.26,1.27 mbox-storage.c,1.20,1.21
cras at procontrol.fi
cras at procontrol.fi
Thu Dec 19 03:02:38 EET 2002
- Previous message: [dovecot-cvs] dovecot/src/lib hostpid.c,1.3,1.4 mempool-alloconly.c,1.10,1.11 network.c,1.14,1.15 ostream.c,1.1,1.2 ostream.h,1.1,1.2 process-title.c,1.2,1.3 restrict-access.c,1.6,1.7 strfuncs.c,1.19,1.20 strfuncs.h,1.9,1.10 unlink-directory.c,1.2,1.3 Message-Id: <20021219010237.74222238C2@danu.procontrol.fi>
- Next message: [dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-copy.c,1.14,1.15 maildir-expunge.c,1.7,1.8 maildir-list.c,1.4,1.5 maildir-save.c,1.11,1.12 maildir-storage.c,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /home/cvs/dovecot/src/lib-storage/index/mbox
In directory danu:/tmp/cvs-serv11467/lib-storage/index/mbox
Modified Files:
mbox-list.c mbox-save.c mbox-storage.c
Log Message:
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Added str_path() and str_ppath() functions. i_snprintf() now returns only -1
or 0 depending on if buffer got full. dec2str() returns the string allocated
from data stack. Instead of just casting to (long) or (int), we now use
dec2str() with printf-like functions. Added o_stream_send_str(). Added
strocpy() and replaced all strcpy()s and strncpy()s with it.
Pretty much untested, hope it doesn't break too badly :)
Index: mbox-list.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-list.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- mbox-list.c 17 Dec 2002 04:52:59 -0000 1.4
+++ mbox-list.c 19 Dec 2002 01:02:35 -0000 1.5
@@ -23,7 +23,7 @@
struct dirent *d;
struct stat st;
const char *dir, *listpath;
- char fulldir[1024], path[1024], fullpath[1024];
+ char fulldir[PATH_MAX], path[PATH_MAX], fullpath[PATH_MAX];
int failed, match;
size_t len;
@@ -32,8 +32,13 @@
if (relative_dir == NULL)
dir = storage->dir;
else {
- i_snprintf(fulldir, sizeof(fulldir), "%s/%s",
- storage->dir, relative_dir);
+ if (str_path(fulldir, sizeof(fulldir),
+ storage->dir, relative_dir) < 0) {
+ mail_storage_set_critical(storage, "Path too long: %s",
+ relative_dir);
+ return FALSE;
+ }
+
dir = fulldir;
}
@@ -70,8 +75,14 @@
if (relative_dir == NULL)
listpath = fname;
else {
- i_snprintf(path, sizeof(path), "%s/%s",
- relative_dir, fname);
+ if (str_path(path, sizeof(path),
+ relative_dir, fname) < 0) {
+ mail_storage_set_critical(storage,
+ "Path too long: %s/%s",
+ relative_dir, fname);
+ failed = TRUE;
+ break;
+ }
listpath = path;
}
@@ -79,7 +90,14 @@
continue;
/* see if it's a directory */
- i_snprintf(fullpath, sizeof(fullpath), "%s/%s", dir, fname);
+ if (str_path(fullpath, sizeof(fullpath), dir, fname) < 0) {
+ mail_storage_set_critical(storage,
+ "Path too long: %s/%s",
+ dir, fname);
+ failed = TRUE;
+ break;
+ }
+
if (stat(fullpath, &st) != 0) {
if (errno == ENOENT)
continue; /* just deleted, ignore */
@@ -169,15 +187,15 @@
FindSubscribedContext *ctx = context;
MailboxFlags flags;
struct stat st;
- char path[1024];
+ char path[PATH_MAX];
/* see if the mailbox exists, don't bother with the marked flags */
if (strcasecmp(name, "INBOX") == 0) {
/* inbox always exists */
flags = 0;
} else {
- i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
- flags = stat(path, &st) == 0 && !S_ISDIR(st.st_mode) ?
+ flags = str_path(path, sizeof(path), storage->dir, name) == 0 &&
+ stat(path, &st) == 0 && !S_ISDIR(st.st_mode) ?
0 : MAILBOX_NOSELECT;
}
Index: mbox-save.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-save.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mbox-save.c 6 Dec 2002 01:09:23 -0000 1.26
+++ mbox-save.c 19 Dec 2002 01:02:35 -0000 1.27
@@ -78,7 +78,6 @@
const char *mbox_path, time_t internal_date)
{
const char *sender, *line, *name;
- size_t len;
if (*my_hostdomain == '\0') {
struct hostent *hent;
@@ -92,17 +91,15 @@
name = my_hostname;
}
- strncpy(my_hostdomain, name, 255);
- my_hostdomain[255] = '\0';
+ strocpy(my_hostdomain, name, 256);
}
sender = t_strconcat(storage->user, "@", my_hostdomain, NULL);
/* save in local timezone, no matter what it was given with */
line = mbox_from_create(sender, internal_date);
- len = strlen(line);
- if (o_stream_send(output, line, len) < 0)
+ if (o_stream_send_str(output, line) < 0)
return write_error(storage, mbox_path);
return TRUE;
@@ -120,7 +117,7 @@
return TRUE;
if (flags & MAIL_SEEN) {
- if (o_stream_send(output, "Status: R\n", 10) < 0)
+ if (o_stream_send_str(output, "Status: R\n") < 0)
return write_error(storage, mbox_path);
}
@@ -132,12 +129,12 @@
(flags & MAIL_DELETED) ? "T" : "",
"\n", NULL);
- if (o_stream_send(output, str, strlen(str)) < 0)
+ if (o_stream_send_str(output, str) < 0)
return write_error(storage, mbox_path);
}
if (flags & MAIL_CUSTOM_FLAGS_MASK) {
- if (o_stream_send(output, "X-Keywords:", 11) < 0)
+ if (o_stream_send_str(output, "X-Keywords:") < 0)
return write_error(storage, mbox_path);
field = 1 << MAIL_CUSTOM_FLAG_1_BIT;
@@ -146,8 +143,8 @@
if (o_stream_send(output, " ", 1) < 0)
return write_error(storage, mbox_path);
- if (o_stream_send(output, custom_flags[i],
- strlen(custom_flags[i])) < 0)
+ if (o_stream_send_str(output,
+ custom_flags[i]) < 0)
return write_error(storage, mbox_path);
}
}
Index: mbox-storage.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- mbox-storage.c 3 Dec 2002 23:29:09 -0000 1.20
+++ mbox-storage.c 19 Dec 2002 01:02:35 -0000 1.21
@@ -145,10 +145,11 @@
static void verify_inbox(MailStorage *storage)
{
- char path[1024];
+ char path[PATH_MAX];
int fd;
- i_snprintf(path, sizeof(path), "%s/inbox", storage->dir);
+ if (str_path(path, sizeof(path), storage->dir, "inbox") < 0)
+ return;
/* make sure inbox file itself exists */
fd = open(path, O_RDWR | O_CREAT | O_EXCL, 0660);
@@ -191,7 +192,7 @@
int readonly, int fast)
{
struct stat st;
- char path[1024];
+ char path[PATH_MAX];
mail_storage_clear_error(storage);
@@ -207,8 +208,8 @@
return FALSE;
}
- i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
- if (stat(path, &st) == 0) {
+ if (str_path(path, sizeof(path), storage->dir, name) == 0 &&
+ stat(path, &st) == 0) {
/* exists - make sure the required directories are also there */
(void)create_mbox_index_dirs(path, TRUE);
@@ -227,7 +228,7 @@
static int mbox_create_mailbox(MailStorage *storage, const char *name)
{
struct stat st;
- char path[1024];
+ char path[PATH_MAX];
int fd;
mail_storage_clear_error(storage);
@@ -241,7 +242,12 @@
}
/* make sure it doesn't exist already */
- i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
+ if (str_path(path, sizeof(path), storage->dir, name) < 0) {
+ mail_storage_set_error(storage, "Mailbox name too long: %s",
+ name);
+ return FALSE;
+ }
+
if (stat(path, &st) == 0) {
mail_storage_set_error(storage, "Mailbox already exists");
return FALSE;
@@ -272,7 +278,7 @@
static int mbox_delete_mailbox(MailStorage *storage, const char *name)
{
const char *index_dir;
- char path[1024];
+ char path[PATH_MAX];
mail_storage_clear_error(storage);
@@ -286,16 +292,22 @@
return FALSE;
}
+ if (str_path(path, sizeof(path), storage->dir, name) < 0) {
+ mail_storage_set_error(storage, "Mailbox name too long: %s",
+ name);
+ return FALSE;
+ }
+
/* first unlink the mbox file */
- i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
if (unlink(path) == -1) {
if (errno == ENOENT) {
mail_storage_set_error(storage,
"Mailbox doesn't exist: %s",
name);
} else {
- mail_storage_set_critical(storage, "Can't delete mbox "
- "file %s: %m", path);
+ mail_storage_set_critical(storage,
+ "Can't delete mbox file "
+ "%s: %m", path);
}
return FALSE;
}
@@ -314,7 +326,7 @@
const char *newname)
{
const char *old_indexdir, *new_indexdir;
- char oldpath[1024], newpath[1024];
+ char oldpath[PATH_MAX], newpath[PATH_MAX];
mail_storage_clear_error(storage);
@@ -327,14 +339,22 @@
if (strcasecmp(oldname, "INBOX") == 0)
oldname = "inbox";
+ if (str_path(oldpath, sizeof(oldpath), storage->dir, oldname) < 0) {
+ mail_storage_set_error(storage, "Mailbox name too long: %s",
+ oldname);
+ return FALSE;
+ }
+ if (str_path(newpath, sizeof(newpath), storage->dir, newname) < 0) {
+ mail_storage_set_error(storage, "Mailbox name too long: %s",
+ newname);
+ return FALSE;
+ }
+
/* NOTE: renaming INBOX works just fine with us, it's simply created
the next time it's needed. */
- i_snprintf(oldpath, sizeof(oldpath), "%s/%s", storage->dir, oldname);
- i_snprintf(newpath, sizeof(newpath), "%s/%s", storage->dir, newname);
- if (link(oldpath, newpath) == 0) {
+ if (link(oldpath, newpath) == 0)
(void)unlink(oldpath);
- /* ... */
- } else if (errno == EEXIST) {
+ else if (errno == EEXIST) {
mail_storage_set_error(storage,
"Target mailbox already exists");
return FALSE;
@@ -356,7 +376,7 @@
MailboxNameStatus *status)
{
struct stat st;
- char path[1024];
+ char path[PATH_MAX];
mail_storage_clear_error(storage);
@@ -368,7 +388,12 @@
return TRUE;
}
- i_snprintf(path, sizeof(path), "%s/%s", storage->dir, name);
+ if (str_path(path, sizeof(path), storage->dir, name) < 0) {
+ mail_storage_set_error(storage, "Mailbox name too long: %s",
+ name);
+ return FALSE;
+ }
+
if (stat(path, &st) == 0) {
*status = MAILBOX_NAME_EXISTS;
return TRUE;
- Previous message: [dovecot-cvs] dovecot/src/lib hostpid.c,1.3,1.4 mempool-alloconly.c,1.10,1.11 network.c,1.14,1.15 ostream.c,1.1,1.2 ostream.h,1.1,1.2 process-title.c,1.2,1.3 restrict-access.c,1.6,1.7 strfuncs.c,1.19,1.20 strfuncs.h,1.9,1.10 unlink-directory.c,1.2,1.3 Message-Id: <20021219010237.74222238C2@danu.procontrol.fi>
- Next message: [dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-copy.c,1.14,1.15 maildir-expunge.c,1.7,1.8 maildir-list.c,1.4,1.5 maildir-save.c,1.11,1.12 maildir-storage.c,1.16,1.17
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the dovecot-cvs
mailing list