Skip to content

Commit

Permalink
flaws found by #coverity fixed
Browse files Browse the repository at this point in the history
All 'High impact' defects handled.
  • Loading branch information
pjstevns committed Sep 4, 2013
1 parent be8354b commit 6e8be98
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 134 deletions.
8 changes: 4 additions & 4 deletions src/dbmailtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ typedef struct {

Field_T clientname; /* resolved client name */

char src_ip[NI_MAXHOST]; /* client IP-number */
char src_port[NI_MAXSERV]; /* client port number */
char src_ip[NI_MAXHOST+1]; /* client IP-number */
char src_port[NI_MAXSERV+1]; /* client port number */

char dst_ip[NI_MAXHOST]; /* server IP-number */
char dst_port[NI_MAXSERV]; /* server port number */
char dst_ip[NI_MAXHOST+1]; /* server IP-number */
char dst_port[NI_MAXSERV+1]; /* server port number */

struct timeval *timeout; /**< timeout on socket */

Expand Down
2 changes: 2 additions & 0 deletions src/dm_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ int config_create(const char *config_filename)
serr = errno;
TRACE(TRACE_EMERG, "error writing [%s] %s",
config_filename, strerror(serr));
close(fd);
return -1;
}

close(fd);
return 0;
}

Expand Down
44 changes: 35 additions & 9 deletions src/dm_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,32 @@

// Flag order defined in dbmailtypes.h
static const char *db_flag_desc[] = {
"seen_flag", "answered_flag", "deleted_flag", "flagged_flag", "draft_flag", "recent_flag" };
"seen_flag",
"answered_flag",
"deleted_flag",
"flagged_flag",
"draft_flag",
"recent_flag",
NULL
};
const char *imap_flag_desc[] = {
"Seen", "Answered", "Deleted", "Flagged", "Draft", "Recent" };
"Seen",
"Answered",
"Deleted",
"Flagged",
"Draft",
"Recent",
NULL
};
const char *imap_flag_desc_escaped[] = {
"\\Seen", "\\Answered", "\\Deleted", "\\Flagged", "\\Draft", "\\Recent" };
"\\Seen",
"\\Answered",
"\\Deleted",
"\\Flagged",
"\\Draft",
"\\Recent",
NULL
};

extern ServerConfig_T *server_conf;
extern DBParam_T db_params;
Expand Down Expand Up @@ -536,7 +557,7 @@ uint64_t db_insert_result(Connection_T c, ResultSet_T r)
{
uint64_t id = 0;

db_result_next(r);
if (! db_result_next(r)) { /* ignore */ }

// lastRowId is always zero for pgsql tables without OIDs
// or possibly for sqlite after calling executeQuery but
Expand Down Expand Up @@ -2024,7 +2045,7 @@ static int db_findmailbox_owner(const char *name, uint64_t owner_idnr,
PreparedStatement_T stmt;
int p;
INIT_QUERY;
const char *frag;
const char *frag = NULL;

assert(mailbox_idnr);
*mailbox_idnr = 0;
Expand All @@ -2034,7 +2055,7 @@ static int db_findmailbox_owner(const char *name, uint64_t owner_idnr,
mailbox_like = mailbox_match_new(name);
if (mailbox_like->sensitive)
frag = db_get_sql(SQL_SENSITIVE_LIKE);
else if (mailbox_like->insensitive)
else
frag = db_get_sql(SQL_INSENSITIVE_LIKE);

snprintf(query, DEF_QUERYSIZE-1,
Expand All @@ -2047,7 +2068,7 @@ static int db_findmailbox_owner(const char *name, uint64_t owner_idnr,
db_stmt_set_u64(stmt, p++, owner_idnr);
if (mailbox_like->sensitive)
db_stmt_set_str(stmt, p++, mailbox_like->sensitive);
else if (mailbox_like->insensitive)
else
db_stmt_set_str(stmt, p++, mailbox_like->insensitive);

r = db_stmt_query(stmt);
Expand Down Expand Up @@ -2353,10 +2374,15 @@ GList * db_imap_split_mailbox(const char *mailbox, uint64_t owner_idnr, const ch
*errmsg = "Public user required for #Public folder access.";
goto egeneral;
}
db_findmailbox(cpy, public, &mboxid);
if (! db_findmailbox(cpy, public, &mboxid)) {
*errmsg = "Public folder not found.";
goto egeneral;
}

} else {
db_findmailbox(cpy, owner_idnr, &mboxid);
if (! db_findmailbox(cpy, owner_idnr, &mboxid)) {
/* ignore */
}
}

/* Prepend a mailbox struct onto the list. */
Expand Down
4 changes: 2 additions & 2 deletions src/dm_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ void trace(Trace_T level, const char * module, const char * function, int line,
}

/* Bail out on fatal errors. */
// if (level == TRACE_EMERG)
// exit(EX_TEMPFAIL);
if (level == TRACE_EMERG)
exit(EX_TEMPFAIL);
}


2 changes: 1 addition & 1 deletion src/dm_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void Http_getUsers(T R)
/* Check if the user has ACL delete rights to this mailbox */
M = MailboxState_new(NULL, mboxid);
access = acl_has_right(M, id, ACL_RIGHT_DELETE);
MailboxState_free(&M);
if (access != 1) {
Request_error(R, HTTP_BADREQUEST, "NO permission denied");
evbuffer_free(buf);
Expand All @@ -117,7 +118,6 @@ void Http_getUsers(T R)
}
}


users = g_list_append_printf(users, "%s", username);
} else {
/*
Expand Down
14 changes: 8 additions & 6 deletions src/dm_imapsession.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ static void _fetch_headers(ImapSession *self, body_fetch *bodyfetch, gboolean no
GString *fieldorder = NULL;
int k;
int fieldseq;
String_T query = p_string_new(self->pool, "");
String_T range = p_string_new(self->pool, "");
String_T query;
String_T range;

if (! bodyfetch->headers) {
TRACE(TRACE_DEBUG, "[%p] init bodyfetch->headers", self);
Expand Down Expand Up @@ -756,7 +756,9 @@ static void _fetch_headers(ImapSession *self, body_fetch *bodyfetch, gboolean no
}

// let's fetch the required message and prefetch a batch if needed.

range = p_string_new(self->pool, "");
query = p_string_new(self->pool, "");

if (! (last = g_list_nth(self->ids_list, self->lo+(uint64_t)QUERY_BATCHSIZE)))
last = g_list_last(self->ids_list);
self->hi = *(uint64_t *)last->data;
Expand Down Expand Up @@ -969,7 +971,7 @@ static void _fetch_envelopes(ImapSession *self)
}

if ((s = g_tree_lookup(self->envelopes, &(self->msg_idnr))) != NULL) {
dbmail_imap_session_buff_printf(self, "ENVELOPE %s", s?s:"");
dbmail_imap_session_buff_printf(self, "ENVELOPE %s", s);
return;
}

Expand Down Expand Up @@ -1429,7 +1431,7 @@ static void notify_fetch(ImapSession *self, MailboxState_T N, uint64_t *uid)
g_list_destroy(ol);
g_list_destroy(nl);

if (old->seq < new->seq)
if ((!old) || (old->seq < new->seq))
modseqchanged = true;
if (oldflags && (! MATCH(oldflags, newflags)))
flagschanged = true;
Expand All @@ -1443,7 +1445,7 @@ static void notify_fetch(ImapSession *self, MailboxState_T N, uint64_t *uid)
}

if (modseqchanged && self->mailbox->condstore) {
TRACE(TRACE_DEBUG, "seq [%" PRIu64 "] -> [%" PRIu64 "]", old->seq, new->seq);
TRACE(TRACE_DEBUG, "seq [%" PRIu64 "] -> [%" PRIu64 "]", old?old->seq:0, new->seq);
char *m = g_strdup_printf("MODSEQ (%" PRIu64 ")", new->seq);
plist = g_list_append(plist, m);
}
Expand Down
Loading

0 comments on commit 6e8be98

Please sign in to comment.