Use strfcpy instead of strncpy. The current logic could write past the end of the buffer.
Don't mess with BUFFY next pointers during removal. The mutt_parse_mailboxes() is fine, but this is still not something that should be done inside sidebar.c. On removal, set next->prev since we can. Fix unmailboxes logic: * only fix the prev pointers once. * if we unmailbox the open mailbox, set it to NULL. Lastly, flag a redraw on mailboxes/unmailboxes. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1464748766 25200 # Tue May 31 19:39:26 2016 -0700 # Node ID f6be3ce526d4a49a300fc2853d10521ce044ee21 # Parent dad3729fc54fb1a15c253dd103117383a3e1054e Various fixes to the sidebar logic. Use strfcpy instead of strncpy. The current logic could write past the end of the buffer. Don't mess with BUFFY next pointers during removal. The mutt_parse_mailboxes() is fine, but this is still not something that should be done inside sidebar.c. On removal, set next->prev since we can. Fix unmailboxes logic: * only fix the prev pointers once. * if we unmailbox the open mailbox, set it to NULL. Lastly, flag a redraw on mailboxes/unmailboxes. diff --git a/sidebar.c b/sidebar.c --- a/sidebar.c +++ b/sidebar.c @@ -258,20 +258,17 @@ BUFFY *b) { struct sidebar_entry sbe; if (!buf || !box || !b) return; sbe.buffy = b; - strncpy (sbe.box, box, sizeof (sbe.box) - 1); - - int box_len = strlen (box); - sbe.box[box_len] = '\0'; + strfcpy (sbe.box, box, sizeof (sbe.box)); mutt_FormatString (buf, buflen, 0, width, NONULL(SidebarFormat), cb_format_str, (unsigned long) &sbe, 0); /* Force string to be exactly the right width */ int w = mutt_strwidth (buf); int s = strlen (buf); if (w < width) { @@ -350,22 +347,19 @@ * Returns: * A valid alternative BUFFY, or NULL */ static BUFFY *buffy_going (const BUFFY *b) { if (!b) return NULL; - if (b->prev) - b->prev->next = NULL; - if (b->next) { - b->next->prev = NULL; + b->next->prev = b->prev; return b->next; } return b->prev; } /** * update_buffy_visibility - Should a BUFFY be displayed in the sidebar @@ -969,20 +963,23 @@ /* This might happen if the user "unmailboxes *", then * "mailboxes" our current mailbox back again */ if (mutt_strcmp (b->path, Context->path) == 0) OpnBuffy = b; } } else { + BUFFY *replacement = buffy_going (b); if (TopBuffy == b) - TopBuffy = buffy_going (TopBuffy); + TopBuffy = replacement; if (OpnBuffy == b) - OpnBuffy = buffy_going (OpnBuffy); + OpnBuffy = NULL; if (HilBuffy == b) - HilBuffy = buffy_going (HilBuffy); + HilBuffy = replacement; if (BotBuffy == b) - BotBuffy = buffy_going (BotBuffy); + BotBuffy = replacement; if (Outgoing == b) - Outgoing = buffy_going (Outgoing); + Outgoing = replacement; } + + SidebarNeedsRedraw = 1; }
signature.asc
Description: PGP signature
