From f3cbb9f51357972f6e74244494236a41dc4d84cd Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 28 Nov 2006 18:59:29 +0100 Subject: [PATCH] Use good m_ functions, because it smell like a flower, version 2. 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 Signed-off-by: Pierre Habouzit --- attach.c | 6 ++---- browser.c | 6 +++--- copy.c | 35 ++++++++++++++++++++--------------- dotlock.c | 2 +- handler.c | 2 +- imap/auth_gss.c | 2 +- init.c | 4 ++-- lib-crypt/crypt-gpgme.c | 16 +++++++++------- lib-crypt/pgp.c | 4 ++-- lib-crypt/pgpinvoke.c | 2 +- lib-crypt/pgpkey.c | 12 ++++++------ lib-crypt/pgppacket.c | 2 +- lib-crypt/smime.c | 8 ++++---- lib-mime/rfc1524.c | 2 +- lib-mime/rfc2231.c | 2 +- lib-mime/rfc3676.c | 2 +- lib-mime/rfc822address.c | 2 +- lib-mime/rfc822parse.c | 4 ++-- lib-mx/mh.c | 2 +- lib-ui/complete.c | 2 +- lib-ui/curs_lib.c | 4 ++-- lib-ui/query.c | 2 +- lib-ui/sidebar.c | 2 +- makedoc.c | 16 ++++++++-------- mutt_idna.c | 6 +++--- mutt_libesmtp.c | 2 +- mutt_sasl.c | 2 +- muttlib.c | 2 +- pgpewrap.c | 2 +- pop/pop.c | 10 ++++++---- pop/pop_lib.c | 12 +++++++----- recvattach.c | 6 +++--- send.c | 4 ++-- sendlib.c | 2 +- state.c | 4 ++-- 35 files changed, 101 insertions(+), 92 deletions(-) diff --git a/attach.c b/attach.c index d4b1c6f..5d9b51f 100644 --- a/attach.c +++ b/attach.c @@ -45,7 +45,7 @@ int mutt_get_tmp_attachment (BODY * a) 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; @@ -666,7 +666,7 @@ static FILE *mutt_save_attachment_open (char *path, int flags) * 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"); } @@ -784,8 +784,6 @@ int mutt_decode_save_attachment (FILE * fp, BODY * m, char *path, 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"); diff --git a/browser.c b/browser.c index 52fbb06..43b1b34 100644 --- a/browser.c +++ b/browser.c @@ -778,7 +778,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, } else { if (f[0] == '/') - strcpy (LastDir, "/"); /* __STRCPY_CHECKED__ */ + m_strcpy(LastDir, sizeof(LastDir), "/"); else getcwd (LastDir, sizeof (LastDir)); } @@ -869,7 +869,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, 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, '/'); @@ -879,7 +879,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, if (LastDir[0] == '/') LastDir[1] = 0; else - strcat (LastDir, "/.."); /* __STRCAT_CHECKED__ */ + m_strcat(LastDir, sizeof(LastDir), "/.."); } } } diff --git a/copy.c b/copy.c index 5e0b7db..0c5f8b4 100644 --- a/copy.c +++ b/copy.c @@ -39,6 +39,7 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, int hdr_count; int x; char *this_one = NULL; + ssize_t this_one_len = 0, headers_len = 0; int error; int curline = 0; @@ -140,8 +141,9 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t 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); } @@ -207,13 +209,15 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t off_end, * 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) */ @@ -228,8 +232,9 @@ mutt_copy_hdr (FILE* in, FILE* out, off_t off_start, off_t 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); } @@ -794,12 +799,12 @@ static void format_address_header (char **h, address_t * a) 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; @@ -807,18 +812,18 @@ static void format_address_header (char **h, address_t * a) 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) diff --git a/dotlock.c b/dotlock.c index abf92f0..8d562c8 100644 --- a/dotlock.c +++ b/dotlock.c @@ -85,7 +85,7 @@ int main (int argc, char **argv) /* 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'; diff --git a/handler.c b/handler.c index 51f4c32..c72ddfc 100644 --- a/handler.c +++ b/handler.c @@ -483,7 +483,7 @@ static void enriched_flush (struct enriched_state *stte, int wrap) 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; diff --git a/imap/auth_gss.c b/imap/auth_gss.c index 978d5a4..6e82a26 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -173,7 +173,7 @@ imap_auth_res_t imap_auth_gss (IMAP_DATA * idata, const char *method __attribute 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, diff --git a/init.c b/init.c index 6aad1d7..21bdd4f 100644 --- a/init.c +++ b/init.c @@ -1034,7 +1034,7 @@ static int parse_attach_list (BUFFER *buf, BUFFER *s, string_list_t **ldata, 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'; @@ -2505,7 +2505,7 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) 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)); diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index 4737fed..7e3495b 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -1002,6 +1002,7 @@ static void show_fingerprint (gpgme_key_t key, STATE * state) int i, is_pgp; char *buf, *p; const char *prefix = _("Fingerprint: "); + ssize_t bufsize; if (!key) return; @@ -1010,8 +1011,9 @@ static void show_fingerprint (gpgme_key_t key, STATE * state) 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++) { @@ -3257,15 +3259,15 @@ static crypt_key_t *crypt_select_key (crypt_key_t * keys, 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; @@ -3707,7 +3709,7 @@ static char *find_keys (address_t * to, address_t * cc, address_t * bcc, 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); diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 3c3e0f7..7a23728 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -695,7 +695,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) 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); } @@ -1087,7 +1087,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) 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); diff --git a/lib-crypt/pgpinvoke.c b/lib-crypt/pgpinvoke.c index b3d42a2..39c10ad 100644 --- a/lib-crypt/pgpinvoke.c +++ b/lib-crypt/pgpinvoke.c @@ -316,7 +316,7 @@ pid_t pgp_invoke_list_keys (FILE ** pgpin, FILE ** pgpout, FILE ** pgperr, 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, diff --git a/lib-crypt/pgpkey.c b/lib-crypt/pgpkey.c index 16d9e4c..033c0e8 100644 --- a/lib-crypt/pgpkey.c +++ b/lib-crypt/pgpkey.c @@ -466,15 +466,15 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, address_t * p, const char *s) 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; @@ -500,7 +500,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, address_t * p, const char *s) 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; @@ -694,7 +694,7 @@ BODY *pgp_make_key_attachment (char *tempf) 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); diff --git a/lib-crypt/pgppacket.c b/lib-crypt/pgppacket.c index d003154..2cfddbb 100644 --- a/lib-crypt/pgppacket.c +++ b/lib-crypt/pgppacket.c @@ -27,7 +27,7 @@ static int read_material (size_t material, size_t * used, FILE * fp) nplen = *used + material + CHUNKSIZE; - if (!(p = realloc (pbuf, nplen))) { /* __MEM_CHECKED__ */ + if (!(p = realloc(pbuf, nplen))) { perror ("realloc"); return -1; } diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 5906f68..1248f31 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -404,12 +404,12 @@ char *smime_ask_for_key (char *prompt, char *mailbox __attribute__((unused)), /* 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 (); @@ -754,7 +754,7 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) 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); diff --git a/lib-mime/rfc1524.c b/lib-mime/rfc1524.c index 39e46e6..8705ace 100644 --- a/lib-mime/rfc1524.c +++ b/lib-mime/rfc1524.c @@ -301,7 +301,7 @@ rfc1524_mailcap_parse(BODY *a, const char *filename, const char *type, 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); diff --git a/lib-mime/rfc2231.c b/lib-mime/rfc2231.c index 7cd45d2..287c1d6 100644 --- a/lib-mime/rfc2231.c +++ b/lib-mime/rfc2231.c @@ -175,7 +175,7 @@ rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) 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; diff --git a/lib-mime/rfc3676.c b/lib-mime/rfc3676.c index 253c231..42bf5ac 100644 --- a/lib-mime/rfc3676.c +++ b/lib-mime/rfc3676.c @@ -187,7 +187,7 @@ int rfc3676_handler (BODY * a, STATE * s) { } 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 */ diff --git a/lib-mime/rfc822address.c b/lib-mime/rfc822address.c index 6c11e63..190588c 100644 --- a/lib-mime/rfc822address.c +++ b/lib-mime/rfc822address.c @@ -37,7 +37,7 @@ void rfc822_qualify(address_t *addr, const char *host) 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; } diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 1bafc6b..269b43e 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -116,8 +116,8 @@ string_list_t *mutt_parse_references(char *s, int in_reply_to) 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); } } diff --git a/lib-mx/mh.c b/lib-mx/mh.c index 7325b0c..7225ccc 100644 --- a/lib-mx/mh.c +++ b/lib-mx/mh.c @@ -1680,7 +1680,7 @@ static FILE *_maildir_open_find_message (const char *folder, const char *unique, 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; } diff --git a/lib-ui/complete.c b/lib-ui/complete.c index 97f5b2d..511fee0 100644 --- a/lib-ui/complete.c +++ b/lib-ui/complete.c @@ -78,7 +78,7 @@ int mutt_complete (char *s, ssize_t slen) } } - strcpy (s, filepart); + m_strcpy(s, slen, filepart); return (init ? 0 : -1); } diff --git a/lib-ui/curs_lib.c b/lib-ui/curs_lib.c index 762cfbb..81a817b 100644 --- a/lib-ui/curs_lib.c +++ b/lib-ui/curs_lib.c @@ -443,7 +443,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, ssize_t blen, 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, @@ -609,7 +609,7 @@ void mutt_format_string (char *dest, ssize_t destlen, break; min_width -= w; max_width -= w; - strncpy (p, scratch, k2); + m_strncpy(p, destlen, scratch, k2); p += k2; destlen -= k2; } diff --git a/lib-ui/query.c b/lib-ui/query.c index b0a42d7..2ce8961 100644 --- a/lib-ui/query.c +++ b/lib-ui/query.c @@ -434,7 +434,7 @@ static void query_menu (char *buf, ssize_t buflen, QUERY * results, int retbuf) 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); diff --git a/lib-ui/sidebar.c b/lib-ui/sidebar.c index 6668ca0..6ccff9f 100644 --- a/lib-ui/sidebar.c +++ b/lib-ui/sidebar.c @@ -82,7 +82,7 @@ static char *shortened_hierarchy (char *hbox, int maxlen) 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; } } diff --git a/makedoc.c b/makedoc.c index f68f969..6451c48 100644 --- a/makedoc.c +++ b/makedoc.c @@ -462,17 +462,17 @@ static void char_to_escape (char *dest, unsigned int c) { 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; diff --git a/mutt_idna.c b/mutt_idna.c index c728e5e..1a9bd8b 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -151,7 +151,7 @@ int mutt_addrlist_to_idna (address_t * a, char **err) } 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); @@ -178,7 +178,7 @@ int mutt_addrlist_to_local (address_t * a) 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); @@ -212,7 +212,7 @@ const char *mutt_addr_for_display (address_t * a) } 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); diff --git a/mutt_libesmtp.c b/mutt_libesmtp.c index c217298..9df7ffb 100644 --- a/mutt_libesmtp.c +++ b/mutt_libesmtp.c @@ -158,7 +158,7 @@ static const char *_mutt_libesmtp_messagefp_cb (void **buf, int *len, 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; diff --git a/mutt_sasl.c b/mutt_sasl.c index 6da72b5..f38acda 100644 --- a/mutt_sasl.c +++ b/mutt_sasl.c @@ -302,7 +302,7 @@ static int mutt_sasl_cb_pass(sasl_conn_t *conn __attribute__ ((unused)), *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; } diff --git a/muttlib.c b/muttlib.c index 695d08c..9afd5cd 100644 --- a/muttlib.c +++ b/muttlib.c @@ -846,7 +846,7 @@ int mutt_extract_token(BUFFER *dest, BUFFER *tok, int flags) 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; diff --git a/pgpewrap.c b/pgpewrap.c index bb9b2d0..f149fdc 100644 --- a/pgpewrap.c +++ b/pgpewrap.c @@ -26,7 +26,7 @@ int main (int argc, char **argv) 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); diff --git a/pop/pop.c b/pop/pop.c index 40df878..a40e2f8 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -499,6 +499,7 @@ void pop_fetch_mail (void) MESSAGE *msg = NULL; ACCOUNT act; POP_DATA *pop_data; + ssize_t plen; if (!PopHost) { mutt_error _("POP host is not defined."); @@ -506,12 +507,13 @@ void pop_fetch_mail (void) 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); diff --git a/pop/pop_lib.c b/pop/pop_lib.c index b3bac5a..f4c17e9 100644 --- a/pop/pop_lib.c +++ b/pop/pop_lib.c @@ -94,15 +94,17 @@ static int fetch_capa (char *line, void *data) 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; } diff --git a/recvattach.c b/recvattach.c index 0403bc5..d4ebd3d 100644 --- a/recvattach.c +++ b/recvattach.c @@ -48,7 +48,7 @@ static struct mapping_t AttachHelp[] = { {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; @@ -59,7 +59,7 @@ static int mutt_extract_path (char *filename, char *path) if (*filename == '/') { *help_ptr++ = *filename++; *help_ptr++ = '\0'; - strcat (path, tmp); + m_strcat(path, pathlen, tmp); help_ptr = tmp; } *help_ptr++ = *filename++; @@ -424,7 +424,7 @@ static int mutt_query_save_attachment (FILE * fp, BODY * body, HEADER * hdr, return -1; } else { - mutt_extract_path (buf, path); + mutt_extract_path (buf, path, sizeof(path)); m_strcpy(LastSaveFolder, sizeof(LastSaveFolder), path); } diff --git a/send.c b/send.c index e2666a2..1773589 100644 --- a/send.c +++ b/send.c @@ -603,7 +603,7 @@ void mutt_make_misc_reply_headers (ENVELOPE * env, 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"); @@ -952,7 +952,7 @@ address_t *mutt_default_from (void) 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 (); diff --git a/sendlib.c b/sendlib.c index 4c5219e..8c3d68c 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1534,7 +1534,7 @@ static void encode_headers (string_list_t * h) 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); } diff --git a/state.c b/state.c index 1d41017..eb0a9c7 100644 --- a/state.c +++ b/state.c @@ -87,8 +87,8 @@ void state_prefix_putc (char c, STATE * s) 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); -- 2.20.1