This is a whole bunch of update for using more m_* functions.
Some calculation should be checked, maybe I made some mistakes.
Not good at math.
There is also some _CHECKED__ comments removed because I got
my head checked by a jumbot jet.
Signed-off-by: Julien Danjou <julien@danjou.info>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
if (stat (a->filename, &st) == -1)
return -1;
- if ((fpin = fopen (a->filename, "r")) && (fpout = safe_fopen (tempfile, "w"))) { /* __FOPEN_CHECKED__ */
+ if ((fpin = fopen (a->filename, "r")) && (fpout = safe_fopen (tempfile, "w"))) {
mutt_copy_stream (fpin, fpout);
m_strreplace(&a->filename, tempfile);
a->unlink = 1;
* as safe_fopen returns w/ an error if path exists
*/
if (flags == M_SAVE_OVERWRITE)
- return fopen (path, "w"); /* __FOPEN_CHECKED__ */
+ return fopen (path, "w");
return safe_fopen (path, "w");
}
if (flags == M_SAVE_APPEND)
s.fpout = fopen (path, "a");
- else if (flags == M_SAVE_OVERWRITE)
- s.fpout = safe_fopen (path, "w"); /* __FOPEN_CHECKED__ */
else
s.fpout = safe_fopen (path, "w");
}
else {
if (f[0] == '/')
- strcpy (LastDir, "/"); /* __STRCPY_CHECKED__ */
+ m_strcpy(LastDir, sizeof(LastDir), "/");
else
getcwd (LastDir, sizeof (LastDir));
}
if (m_strcmp(state.entry[menu->current].name, "..") == 0) {
if (m_strcmp("..", LastDir + m_strlen(LastDir) - 2) == 0)
- strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */
+ m_strcat(LastDir, sizeof(LastDir), "/..");
else {
char *p = strrchr (LastDir + 1, '/');
if (LastDir[0] == '/')
LastDir[1] = 0;
else
- strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */
+ m_strcat(LastDir, sizeof(LastDir), "/..");
}
}
}
int hdr_count;
int x;
char *this_one = NULL;
+ ssize_t this_one_len = 0, headers_len = 0;
int error;
int curline = 0;
if (!headers[x])
headers[x] = this_one;
else {
- p_realloc(&headers[x], m_strlen(headers[x]) + m_strlen(this_one) + 1);
- strcat(headers[x], this_one); /* __STRCAT_CHECKED__ */
+ headers_len = m_strlen(headers[x]) + m_strlen(this_one) + 1;
+ p_realloc(&headers[x], headers_len);
+ m_strcat(headers[x], headers_len, this_one);
p_delete(&this_one);
}
* abbreviations (curline is 0), $max_display_recips is 0 and
* while the number hasn't reached $max_display_recips yet */
else if (curline == 0 || MaxDispRecips == 0 || ++curline <= MaxDispRecips) {
- p_realloc(&this_one, m_strlen(this_one) + m_strlen(buf) + 1);
- strcat (this_one, buf); /* __STRCAT_CHECKED__ */
+ this_one_len = m_strlen(this_one) + m_strlen(buf) + 1;
+ p_realloc(&this_one, this_one_len);
+ m_strcat(this_one, this_one_len, buf);
/* only for the first line which doesn't exeeds
* $max_display_recips: abbreviate it */
} else if (curline == MaxDispRecips+1) {
- p_realloc(&this_one, m_strlen(this_one) + 5);
- strcat (this_one, " ...");
+ this_one_len = m_strlen(this_one) + 5;
+ p_realloc(&this_one, this_one_len);
+ m_strcat(this_one, this_one_len, " ...");
}
}
} /* while (ftello (in) < off_end) */
if (!headers[x])
headers[x] = this_one;
else {
- p_realloc(&headers[x], m_strlen(headers[x]) + m_strlen(this_one) + 1);
- strcat (headers[x], this_one); /* __STRCAT_CHECKED__ */
+ headers_len = m_strlen(headers[x]) + m_strlen(this_one) + 1;
+ p_realloc(&headers[x], headers_len);
+ m_strcat(headers[x], headers_len, this_one);
p_delete(&this_one);
}
l = m_strlen(buf);
if (count && linelen + l > 74) {
- strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */
+ m_strcpy(cbuf, sizeof(cbuf), "\n\t");
linelen = l + 8;
}
else {
if (a->mailbox) {
- strcpy (cbuf, " "); /* __STRCPY_CHECKED__ */
+ m_strcpy(cbuf, sizeof(cbuf), " ");
linelen++;
}
linelen += l;
if (!a->group && a->next && a->next->mailbox) {
linelen++;
buflen++;
- strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */
+ m_strcpy(c2buf, sizeof(c2buf), ",");
}
buflen += l + m_strlen(cbuf) + m_strlen(c2buf);
p_realloc(h, buflen);
- strcat (*h, cbuf); /* __STRCAT_CHECKED__ */
- strcat (*h, buf); /* __STRCAT_CHECKED__ */
- strcat (*h, c2buf); /* __STRCAT_CHECKED__ */
+ m_strcat(*h, buflen, cbuf);
+ m_strcat(*h, buflen, buf);
+ m_strcat(*h, buflen, c2buf);
}
/* Space for this was allocated in the beginning of this function. */
- strcat (*h, "\n"); /* __STRCAT_CHECKED__ */
+ m_strcat(*h, buflen, "\n");
}
static int address_header_decode (char **h)
/* determine the system's host name */
uname (&utsname);
- if (!(Hostname = strdup (utsname.nodename))) /* __MEM_CHECKED__ */
+ if (!(Hostname = strdup(utsname.nodename)))
return DL_EX_ERROR;
if ((p = strchr (Hostname, '.')))
*p = '\0';
stte->line_max = stte->line_used;
p_realloc(&stte->line, stte->line_max + 1);
}
- strcat (stte->line, stte->buffer); /* __STRCAT_CHECKED__ */
+ m_strcat(stte->line, stte->line_max + 1, stte->buffer);
stte->line_len += stte->word_len;
stte->word_len = 0;
stte->buff_used = 0;
memcpy (buf1, &buf_size, 4);
buf1[0] = GSS_AUTH_P_NONE;
/* server decides if principal can log in as user */
- strncpy (buf1 + 4, idata->conn->account.user, sizeof (buf1) - 4);
+ m_strcpy(buf1 + 4, sizeof(buf1) - 4, idata->conn->account.user);
request_buf.value = buf1;
request_buf.length = 4 + m_strlen(idata->conn->account.user) + 1;
maj_stat = gss_wrap (&min_stat, context, 0, GSS_C_QOP_DEFAULT, &request_buf,
len = m_strlen(a->minor);
tmpminor = p_new(char, len + 3);
- strcpy(&tmpminor[1], a->minor); /* __STRCPY_CHECKED__ */
+ m_strcpy(&tmpminor[1], len + 3, a->minor);
tmpminor[0] = '^';
tmpminor[len+1] = '$';
tmpminor[len+2] = '\0';
else
if (*buffer != '@') {
Fqdn = p_new(char, m_strlen(buffer) + m_strlen(Hostname) + 2);
- sprintf (Fqdn, "%s.%s", NONULL(Hostname), buffer); /* __SPRINTF_CHECKED__ */
+ sprintf (Fqdn, "%s.%s", NONULL(Hostname), buffer);
}
else
Fqdn = m_strdup(NONULL (Hostname));
int i, is_pgp;
char *buf, *p;
const char *prefix = _("Fingerprint: ");
+ ssize_t bufsize;
if (!key)
return;
return;
is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
- buf = xmalloc(m_strlen(prefix) + m_strlen(s) * 4 + 2);
- strcpy (buf, prefix); /* __STRCPY_CHECKED__ */
+ bufsize = m_strlen(prefix) + m_strlen(s) * 4 + 2;
+ buf = xmalloc(bufsize);
+ m_strcpy(buf, bufsize, prefix);
p = buf + m_strlen(buf);
if (is_pgp && m_strlen(s) == 40) { /* PGP v4 style formatted. */
for (i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++) {
helpstr[0] = 0;
mutt_make_help (buf, sizeof (buf), _("Exit "), menu_to_use, OP_EXIT);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Select "), menu_to_use,
OP_GENERIC_SELECT_ENTRY);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Check key "),
menu_to_use, OP_VERIFY_KEY);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Help"), menu_to_use, OP_HELP);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
menu = mutt_new_menu ();
menu->max = i;
keylist_size += m_strlen(s) + 4 + 1;
p_realloc(&keylist, keylist_size);
- sprintf (keylist + keylist_used, "%s0x%s%s", /* __SPRINTF_CHECKED__ */
+ sprintf (keylist + keylist_used, "%s0x%s%s",
keylist_used ? " " : "", s, forced_valid ? "!" : "");
}
keylist_used = m_strlen(keylist);
while (fgets (buf, sizeof (buf) - 1, pgpout) != NULL) {
len = m_strlen(buf);
if (len > 1 && buf[len - 2] == '\r')
- strcpy (buf + len - 2, "\n"); /* __STRCPY_CHECKED__ */
+ m_strcpy(buf + len - 2, len - 2, "\n");
fputs (buf, fpout);
}
bypass_selection:
keylist_size += m_strlen(keyID) + 4;
p_realloc(&keylist, keylist_size);
- sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */
+ sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "",
keyID);
keylist_used = m_strlen(keylist);
for (; hints; hints = hints->next) {
mutt_quote_filename (quoted, sizeof (quoted), (char *) hints->data);
snprintf (tmpuids, sizeof (tmpuids), "%s %s", uids, quoted);
- strcpy (uids, tmpuids); /* __STRCPY_CHECKED__ */
+ m_strcpy(uids, sizeof(uids), tmpuids);
}
return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd,
helpstr[0] = 0;
mutt_make_help (buf, sizeof (buf), _("Exit "), MENU_PGP, OP_EXIT);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Select "), MENU_PGP,
OP_GENERIC_SELECT_ENTRY);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Check key "), MENU_PGP,
OP_VERIFY_KEY);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Help"), MENU_PGP, OP_HELP);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
menu = mutt_new_menu ();
menu->max = i;
case OP_VERIFY_KEY:
- if ((devnull = fopen ("/dev/null", "w")) == NULL) { /* __FOPEN_CHECKED__ */
+ if ((devnull = fopen("/dev/null", "w")) == NULL) {
mutt_perror (_("Can't open /dev/null"));
break;
return NULL;
}
- if ((devnull = fopen ("/dev/null", "w")) == NULL) { /* __FOPEN_CHECKED__ */
+ if ((devnull = fopen("/dev/null", "w")) == NULL) {
mutt_perror (_("Can't open /dev/null"));
m_fclose(&tempfp);
nplen = *used + material + CHUNKSIZE;
- if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */
+ if (!(p = realloc(pbuf, nplen))) {
perror ("realloc");
return -1;
}
/* Make Helpstring */
helpstr[0] = 0;
mutt_make_help (buf, sizeof (buf), _("Exit "), MENU_SMIME, OP_EXIT);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Select "), MENU_SMIME,
OP_GENERIC_SELECT_ENTRY);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
mutt_make_help (buf, sizeof (buf), _("Help"), MENU_SMIME, OP_HELP);
- strcat (helpstr, buf); /* __STRCAT_CHECKED__ */
+ m_strcat(helpstr, sizeof(helpstr), buf);
/* Create the menu */
menu = mutt_new_menu ();
keylist_size += m_strlen(keyID) + 2;
p_realloc(&keylist, keylist_size);
- sprintf (keylist + keylist_used, "%s\n", keyID); /* __SPRINTF_CHECKED__ */
+ sprintf (keylist + keylist_used, "%s\n", keyID);
keylist_used = m_strlen(keylist);
address_list_wipe(&addr);
ssize_t len = m_strlen(value) + STRING;
char *testcmd = p_new(char, len);
- strcpy(testcmd, value);
+ m_strcpy(testcmd, len, value);
rfc1524_expand_command(a, a->filename, type, testcmd, len);
found = !mutt_system(testcmd);
p_delete(&testcmd);
vl = m_strlen(par->value);
p_realloc(&value, l + vl + 1);
- strcpy (value + l, par->value); /* __STRCPY_CHECKED__ */
+ m_strcpy(value + l, vl + 1, par->value);
l += vl;
q = par->next;
}
p_realloc(&curline, curline_len + buf_len - buf_off);
- strcpy (curline + curline_len - 1, buf + buf_off);
+ m_strcpy(curline + curline_len - 1, buf_len - buf_off + 1, buf + buf_off);
curline_len += buf_len - buf_off;
/* if this was a fixed line the paragraph is finished */
for (; addr; addr = addr->next) {
if (!addr->group && addr->mailbox && !strchr(addr->mailbox, '@')) {
p = p_new(char, m_strlen(addr->mailbox) + m_strlen(host) + 2);
- sprintf(p, "%s@%s", addr->mailbox, host); /* __SPRINTF_CHECKED__ */
+ sprintf(p, "%s@%s", addr->mailbox, host);
p_delete(&addr->mailbox);
addr->mailbox = p;
}
o = NULL;
} else {
new = p_new(char, n + m + 1);
- strcpy(new, o);
- strcpy(new + n, s);
+ m_strcpy(new, n + m + 1, o);
+ m_strcpy(new + n, m + 1, s);
}
}
if (!m_strcmp(tunique, unique)) {
snprintf (fname, sizeof (fname), "%s/%s/%s", folder, subfolder,
de->d_name);
- fp = fopen (fname, "r"); /* __FOPEN_CHECKED__ */
+ fp = fopen(fname, "r");
oe = errno;
break;
}
}
}
- strcpy (s, filepart);
+ m_strcpy(s, slen, filepart);
return (init ? 0 : -1);
}
else {
char *pc = p_new(char, m_strlen(prompt) + 3);
- sprintf (pc, "%s: ", prompt); /* __SPRINTF_CHECKED__ */
+ sprintf(pc, "%s: ", prompt);
mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
if (_mutt_get_field
(pc, buf, blen, (buffy ? M_EFILE : M_FILE) | M_CLEAR, multiple, files,
break;
min_width -= w;
max_width -= w;
- strncpy (p, scratch, k2);
+ m_strncpy(p, destlen, scratch, k2);
p += k2;
destlen -= k2;
}
address_t *tmpa = result_to_addr (QueryTable[i].data);
mutt_addrlist_to_local (tmpa);
- strcat (buf, ", "); /* __STRCAT_CHECKED__ */
+ m_strcat(buf, buflen, ", ");
rfc822_write_address ((char *) buf + curpos + 1,
buflen - curpos - 1, tmpa, 0);
curpos = m_strlen(buf);
new_box[j++] = hbox[i + 1];
new_box[j] = 0;
} else {
- strcat (&new_box[j], last_dot);
+ m_strcat(&new_box[j], maxlen + 1, last_dot);
break;
}
}
{
switch (c) {
case '\r':
- strcpy (dest, "\\r");
- break; /* __STRCPY_CHECKED__ */
+ m_strcpy(dest, "\\r");
+ break;
case '\n':
- strcpy (dest, "\\n");
- break; /* __STRCPY_CHECKED__ */
+ m_strcpy(dest, "\\n");
+ break;
case '\t':
- strcpy (dest, "\\t");
- break; /* __STRCPY_CHECKED__ */
+ m_strcpy(dest, "\\t");
+ break;
case '\f':
- strcpy (dest, "\\f");
- break; /* __STRCPY_CHECKED__ */
+ m_strcpy(dest, "\\f");
+ break;
default:
sprintf (dest, "\\%03o", c);
break;
}
else {
p_realloc(&a->mailbox, m_strlen(user) + m_strlen(tmp) + 2);
- sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
+ sprintf(a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));
}
p_delete(&domain);
if (mutt_idna_to_local (domain, &tmp, 0) == 0) {
p_realloc(&a->mailbox, m_strlen(user) + m_strlen(tmp) + 2);
- sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
+ sprintf(a->mailbox, "%s@%s", NONULL (user), NONULL (tmp));
}
p_delete(&domain);
}
p_realloc(&buff, m_strlen(tmp) + m_strlen(user) + 2);
- sprintf (buff, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */
+ sprintf(buff, "%s@%s", NONULL (user), NONULL (tmp));
p_delete(&tmp);
p_delete(&user);
p_delete(&domain);
char *p = strchr (*buf, '\0');
if (p[-1] == '\n' && p[-2] != '\r') {
- strcpy (p - 1, "\r\n");
+ m_strcpy(p - 1, "\r\n");
p++;
}
octets = p - (char *) *buf;
*psecret = xmalloc(sizeof(sasl_secret_t) + len);
(*psecret)->len = len;
- strcpy((char*)(*psecret)->data, account->pass);
+ m_strcpy((char*)(*psecret)->data, len, account->pass);
return SASL_OK;
}
tok->dsize = expnlen + m_strlen(tok->dptr) + 1;
ptr = xmalloc(tok->dsize);
memcpy(ptr, expn.data, expnlen);
- strcpy(ptr + expnlen, tok->dptr); /* __STRCPY_CHECKED__ */
+ m_strcpy(ptr + expnlen, tok->dsize - expnlen, tok->dptr);
if (tok->destroy)
p_delete(&tok->data);
tok->data = ptr;
print_usage (argv[0]);
}
- opts = malloc ((2 * argc + 1) * sizeof (*opts)); /* __MEM_CHECKED__ */
+ opts = malloc((2 * argc + 1) * sizeof (*opts));
if (!opts) {
perror (argv[0]);
exit (2);
MESSAGE *msg = NULL;
ACCOUNT act;
POP_DATA *pop_data;
+ ssize_t plen;
if (!PopHost) {
mutt_error _("POP host is not defined.");
return;
}
- url = p = p_new(char, strlen (PopHost) + 7);
+ plen = m_strlen(PopHost) + 7;
+ url = p = p_new(char, plen);
if (url_check_scheme (PopHost) == U_UNKNOWN) {
- strcpy (url, "pop://"); /* __STRCPY_CHECKED__ */
- p = strchr (url, '\0');
+ plen -= m_strcpy(url, plen, "pop://");
+ p += plen;
}
- strcpy (p, PopHost); /* __STRCPY_CHECKED__ */
+ m_strcpy(p, plen, PopHost);
ret = pop_parse_path (url, &act);
p_delete(&url);
static int fetch_auth (char *line, void *data)
{
POP_DATA *pop_data = (POP_DATA *) data;
+ ssize_t auth_list_len;
if (!pop_data->auth_list) {
- pop_data->auth_list = p_new(char, strlen(line) + 1);
+ auth_list_len = m_strlen(line) + 1;
+ pop_data->auth_list = p_new(char, auth_list_len);
} else {
- p_realloc(&pop_data->auth_list,
- strlen(pop_data->auth_list) + strlen(line) + 2);
- strcat (pop_data->auth_list, " "); /* __STRCAT_CHECKED__ */
+ auth_list_len = m_strlen(pop_data->auth_list) + m_strlen(line) + 2;
+ p_realloc(&pop_data->auth_list, auth_list_len);
+ m_strcat(pop_data->auth_list, auth_list_len, " ");
}
- strcat (pop_data->auth_list, line); /* __STRCAT_CHECKED__ */
+ m_strcat(pop_data->auth_list, auth_list_len, line);
return 0;
}
{NULL, OP_NULL}
};
-static int mutt_extract_path (char *filename, char *path)
+static int mutt_extract_path (char *filename, char *path, ssize_t pathlen)
{
char *tmp = p_new(char, _POSIX_PATH_MAX);
char *help_ptr;
if (*filename == '/') {
*help_ptr++ = *filename++;
*help_ptr++ = '\0';
- strcat (path, tmp);
+ m_strcat(path, pathlen, tmp);
help_ptr = tmp;
}
*help_ptr++ = *filename++;
return -1;
}
else {
- mutt_extract_path (buf, path);
+ mutt_extract_path (buf, path, sizeof(path));
m_strcpy(LastSaveFolder, sizeof(LastSaveFolder), path);
}
if (curenv->real_subj) {
p_delete(&env->subject);
env->subject = p_new(char, m_strlen(curenv->real_subj) + 5);
- sprintf (env->subject, "Re: %s", curenv->real_subj); /* __SPRINTF_CHECKED__ */
+ sprintf (env->subject, "Re: %s", curenv->real_subj);
}
else if (!env->subject)
env->subject = m_strdup("Re: your mail");
else if (option (OPTUSEDOMAIN)) {
adr = address_new ();
adr->mailbox = p_new(char, m_strlen(Username) + m_strlen(fqdn) + 2);
- sprintf (adr->mailbox, "%s@%s", NONULL (Username), NONULL (fqdn)); /* __SPRINTF_CHECKED__ */
+ sprintf (adr->mailbox, "%s@%s", NONULL (Username), NONULL (fqdn));
}
else {
adr = address_new ();
rfc2047_encode_string (&tmp);
p_realloc(&h->data, m_strlen(h->data) + 2 + m_strlen(tmp) + 1);
- sprintf (h->data + i, ": %s", NONULL (tmp)); /* __SPRINTF_CHECKED__ */
+ sprintf (h->data + i, ": %s", NONULL (tmp));
p_delete(&tmp);
}
for (i = 0; i < offset; i++)
if (Quotebuf[i] != ' ')
j = i;
- strncpy (buf, Quotebuf, j + 1);
- strcpy (buf + j + 1, Quotebuf + j);
+ m_strncpy(buf, sizeof(buf), Quotebuf, j + 1);
+ m_strcpy(buf + j + 1, sizeof(buf) - j - 1, Quotebuf + j);
}
else
snprintf (buf, sizeof (buf), "%s%s", NONULL (s->prefix), Quotebuf);