From: Richard Russon Date: Fri, 5 Oct 2018 22:04:14 +0000 (+0100) Subject: replace strncpy with strfcpy X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fdff05a96966c6e395d40d334e2a8003f3cd7287;p=neomutt replace strncpy with strfcpy strncpy isn't guaranteed to NUL-terminate strings --- diff --git a/browser.c b/browser.c index 6b7818082..110dbc77b 100644 --- a/browser.c +++ b/browser.c @@ -632,7 +632,7 @@ static const char *group_index_format_str(char *buf, size_t buflen, size_t col, break; case 'f': - strncpy(fn, folder->ff->name, sizeof(fn) - 1); + mutt_str_strfcpy(fn, folder->ff->name, sizeof(fn)); snprintf(fmt, sizeof(fmt), "%%%ss", prec); snprintf(buf, buflen, fmt, fn); break; diff --git a/curs_main.c b/curs_main.c index f5d11e88d..f18228e1b 100644 --- a/curs_main.c +++ b/curs_main.c @@ -2070,7 +2070,7 @@ int mutt_index_menu(void) break; } nm_query_window_backward(); - strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf)); + mutt_str_strfcpy(buf, NmQueryWindowCurrentSearch, sizeof(buf)); if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf))) mutt_message(_("Failed to create query, aborting")); else @@ -2089,7 +2089,7 @@ int mutt_index_menu(void) break; } nm_query_window_forward(); - strncpy(buf, NmQueryWindowCurrentSearch, sizeof(buf)); + mutt_str_strfcpy(buf, NmQueryWindowCurrentSearch, sizeof(buf)); if (!nm_uri_from_query(Context->mailbox, buf, sizeof(buf))) mutt_message(_("Failed to create query, aborting")); else @@ -2150,7 +2150,7 @@ int mutt_index_menu(void) const char *path = mutt_sb_get_highlight(); if (!path || !*path) break; - strncpy(buf, path, sizeof(buf)); + mutt_str_strfcpy(buf, path, sizeof(buf)); /* Mark the selected dir for the neomutt browser */ mutt_browser_select_dir(buf); diff --git a/edit.c b/edit.c index f9302bdc0..529ada1f5 100644 --- a/edit.c +++ b/edit.c @@ -483,7 +483,7 @@ int mutt_builtin_editor(const char *path, struct Email *msg, struct Email *cur) case 'r': if (*p) { - strncpy(tmp, p, sizeof(tmp)); + mutt_str_strfcpy(tmp, p, sizeof(tmp)); mutt_expand_path(tmp, sizeof(tmp)); buf = be_snarf_file(tmp, buf, &bufmax, &buflen, true); } diff --git a/imap/imap.c b/imap/imap.c index 642f8ee84..545f70e39 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2608,7 +2608,7 @@ static int imap_tags_edit(struct Context *ctx, const char *tags, char *buf, size *buf = '\0'; if (tags) - strncpy(buf, tags, buflen); + mutt_str_strfcpy(buf, tags, buflen); if (mutt_get_field("Tags: ", buf, buflen, 0) != 0) return -1; diff --git a/menu.c b/menu.c index 795c55115..82abd7db9 100644 --- a/menu.c +++ b/menu.c @@ -317,7 +317,7 @@ static void menu_make_entry(char *buf, size_t buflen, struct Menu *menu, int i) { if (menu->dialog) { - strncpy(buf, menu->dialog[i], buflen); + mutt_str_strfcpy(buf, menu->dialog[i], buflen); menu->current = -1; /* hide menubar */ } else diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index 9ec5090c5..d6d53364d 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -268,7 +268,7 @@ static struct PgpKeyInfo *parse_pub_line(char *buf, int *is_subkey, struct PgpKe time.tm_sec = 0; time.tm_min = 0; time.tm_hour = 12; - strncpy(tstr, p, 11); + mutt_str_strfcpy(tstr, p, sizeof(tstr)); tstr[4] = '\0'; tstr[7] = '\0'; if (mutt_str_atoi(tstr, &time.tm_year) < 0) diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 7b09a9d93..de7724690 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -971,7 +971,7 @@ const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char } break; case 's': - strncpy(fn, acct->host, sizeof(fn) - 1); + mutt_str_strfcpy(fn, acct->host, sizeof(fn)); mutt_str_strlower(fn); snprintf(fmt, sizeof(fmt), "%%%ss", prec); snprintf(buf, buflen, fmt, fn); diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 238c8cbae..08bf26ded 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1938,7 +1938,7 @@ char *nm_uri_from_query(struct Mailbox *mailbox, char *buf, size_t buflen) url_pct_encode(&uri[added], sizeof(uri) - added, buf); - strncpy(buf, uri, buflen); + mutt_str_strfcpy(buf, uri, buflen); buf[buflen - 1] = '\0'; mutt_debug(1, "nm: uri from query '%s'\n", buf); @@ -1988,7 +1988,7 @@ bool nm_normalize_uri(const char *uri, char *buf, size_t buflen) if (!nm_uri_from_query(&tmp_mbox, tmp, sizeof(tmp))) goto gone; - strncpy(buf, tmp, buflen); + mutt_str_strfcpy(buf, tmp, buflen); mutt_debug(2, "#3 (%s) -> %s\n", uri, buf); @@ -2243,7 +2243,7 @@ int nm_description_to_path(const char *desc, char *buf, size_t buflen) { if ((np->m->magic == MUTT_NOTMUCH) && np->m->desc && (strcmp(desc, np->m->desc) == 0)) { - strncpy(buf, np->m->path, buflen); + mutt_str_strfcpy(buf, np->m->path, buflen); buf[buflen - 1] = '\0'; return 0; } @@ -2585,7 +2585,7 @@ static int nm_mbox_sync(struct Context *ctx, int *index_hint) if (edata->oldpath) { - strncpy(old, edata->oldpath, sizeof(old)); + mutt_str_strfcpy(old, edata->oldpath, sizeof(old)); old[sizeof(old) - 1] = '\0'; mutt_debug(2, "nm: fixing obsolete path '%s'\n", old); }