Ticket #3666: (size_trunc_len): fix segfault because of small buffer usage.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Michael Osipov 2016-11-03 10:56:39 +03:00 committed by Andrew Borodin
parent 1cccd80399
commit 3024f309c2
3 changed files with 10 additions and 9 deletions

View File

@ -402,10 +402,10 @@ size_trunc_sep (uintmax_t size, gboolean use_si)
/* --------------------------------------------------------------------------------------------- */
/**
* Print file SIZE to BUFFER, but don't exceed LEN characters,
* not including trailing 0. BUFFER should be at least LEN+1 long.
* This function is called for every file on panels, so avoid
* floating point by any means.
* Print file SIZE to BUFFER, but don't exceed LEN characters, not including trailing 0.
* LEN should be at least 7 long and BUFFER at least LEN+1 long.
*
* This function is called for every file on panels, so avoid floating point by any means.
*
* Units: size units (filesystem sizes are 1K blocks)
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
@ -458,6 +458,8 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
const char *const *sfx = use_si ? units_si : units_iec;
int j = 0;
g_assert (len >= 7);
if (len == 0)
len = 9;
#if SIZEOF_UINTMAX_T == 8

View File

@ -147,7 +147,8 @@ const char *size_trunc (uintmax_t size, gboolean use_si);
const char *size_trunc_sep (uintmax_t size, gboolean use_si);
/* Print file SIZE to BUFFER, but don't exceed LEN characters,
* not including trailing 0. BUFFER should be at least LEN+1 long.
* not including trailing 0. LEN should be at least 7 long
* and BUFFER at least LEN+1 long.
*
* Units: size units (0=bytes, 1=Kbytes, 2=Mbytes, etc.) */
void size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gboolean use_si);

View File

@ -56,8 +56,6 @@
/*** file scope macro definitions ****************************************************************/
#define BUF_TRUNC_LEN 5 /* The length of the line displays the file size */
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
@ -172,9 +170,9 @@ mcview_display_status (WView * view)
tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
else
{
char buffer[BUF_TRUNC_LEN + 1];
char buffer[12];
size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0,
size_trunc_len (buffer, sizeof (buffer) - 1, mcview_get_filesize (view), 0,
panels_options.kilobyte_si);
tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end,
buffer, mcview_may_still_grow (view) ? "+" : " ",