Util-Linux package development
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: Sami Kerola <kerolasa@iki.fi>
Subject: [PATCH 2/4] libsmartcols: fix heap-buffer-overflow [asan]
Date: Mon, 11 Sep 2017 20:57:15 +0100	[thread overview]
Message-ID: <20170911195717.817-2-kerolasa@iki.fi> (raw)
In-Reply-To: <20170911195717.817-1-kerolasa@iki.fi>

This gives room for element 0 in array of column cells.

ERROR: AddressSanitizer: heap-buffer-overflow on address 0x608000000080 at
pc 0x5596bfaaca26 bp 0x7ffd8352a550 sp 0x7ffd83529d00
READ of size 64 at 0x608000000080 thread T0
    #0 0x5596bfaaca25 in __asan_memmove (/home/src/util-linux/.libs/lt-column+0xc2a25)
    #1 0x7f8d53660d1b in scols_line_move_cells /home/src/util-linux/libsmartcols/src/line.c:164:2
    #2 0x7f8d5366502c in scols_table_move_column /home/src/util-linux/libsmartcols/src/table.c:307:3
    #3 0x5596bfb0214b in reorder_table /home/src/util-linux/text-utils/column.c:303:3
    #4 0x5596bfaff7ec in modify_table /home/src/util-linux/text-utils/column.c:393:3
    #5 0x5596bfafdbb6 in main /home/src/util-linux/text-utils/column.c:770:4
    #6 0x7f8d52718f69 in __libc_start_main (/usr/lib/libc.so.6+0x20f69)
    #7 0x5596bfa089b9 in _start (/home/src/util-linux/.libs/lt-column+0x1e9b9)

0x608000000080 is located 0 bytes to the right of 96-byte region [0x608000000020,0x608000000080)

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libsmartcols/src/line.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c
index aa339ce38..a041eeb60 100644
--- a/libsmartcols/src/line.c
+++ b/libsmartcols/src/line.c
@@ -133,7 +133,7 @@ int scols_line_alloc_cells(struct libscols_line *ln, size_t n)
 
 	DBG(LINE, ul_debugobj(ln, "alloc %zu cells", n));
 
-	ce = realloc(ln->cells, n * sizeof(struct libscols_cell));
+	ce = realloc(ln->cells, (n + 1) * sizeof(struct libscols_cell));
 	if (!ce)
 		return -errno;
 
-- 
2.14.1


  reply	other threads:[~2017-09-11 19:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 19:57 [PATCH 1/4] uuidparse: fix stack-buffer-overflow [asan] Sami Kerola
2017-09-11 19:57 ` Sami Kerola [this message]
2017-09-15 11:47   ` [PATCH 2/4] libsmartcols: fix heap-buffer-overflow [asan] Karel Zak
2017-09-11 19:57 ` [PATCH 3/4] logger: fix memory leaks [asan] Sami Kerola
2017-09-15 11:05   ` Karel Zak
2017-09-16  0:54     ` J William Piggott
2017-09-16  7:31       ` Sami Kerola
2017-09-18  8:55         ` Karel Zak
2017-09-18  9:40         ` Karel Zak
2017-09-11 19:57 ` [PATCH 4/4] partx: fix memory leak [asan] Sami Kerola
2017-09-15 11:33 ` [PATCH 1/4] uuidparse: fix stack-buffer-overflow [asan] Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170911195717.817-2-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox