diff options
author | Karel Zak | 2017-09-15 13:43:54 +0200 |
---|---|---|
committer | Karel Zak | 2017-09-15 13:43:54 +0200 |
commit | 1ed968c52651d457300cea92b59fe43c67e6e55a (patch) | |
tree | 683e9549b0ca30413ef7330abe733ea47c5c383e /libsmartcols/src | |
parent | uuidparse:fix stack-buffer-overflow [asan] (diff) | |
download | kernel-qcow2-util-linux-1ed968c52651d457300cea92b59fe43c67e6e55a.tar.gz kernel-qcow2-util-linux-1ed968c52651d457300cea92b59fe43c67e6e55a.tar.xz kernel-qcow2-util-linux-1ed968c52651d457300cea92b59fe43c67e6e55a.zip |
libsmartcols: fix heap-buffer-overflow when move columns
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src')
-rw-r--r-- | libsmartcols/src/line.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c index aa339ce38..c2a991c2d 100644 --- a/libsmartcols/src/line.c +++ b/libsmartcols/src/line.c @@ -160,13 +160,15 @@ int scols_line_move_cells(struct libscols_line *ln, size_t newn, size_t oldn) /* remember data from old position */ memcpy(&ce, &ln->cells[oldn], sizeof(struct libscols_cell)); - /* remove from old position */ - memmove(ln->cells + oldn, ln->cells + oldn + 1, + /* remove old possition (move data behind oldn to oldn) */ + if (oldn + 1 < ln->ncells) + memmove(ln->cells + oldn, ln->cells + oldn + 1, (ln->ncells - oldn) * sizeof(struct libscols_cell)); /* create a space for new position */ - memmove(ln->cells + newn + 1, ln->cells + newn, - (ln->ncells - newn) * sizeof(struct libscols_cell)); + if (newn + 1 < ln->ncells) + memmove(ln->cells + newn + 1, ln->cells + newn, + (ln->ncells - newn) * sizeof(struct libscols_cell)); /* copy original data to new position */ memcpy(&ln->cells[newn], &ce, sizeof(struct libscols_cell)); |