Mercurial > octave
changeset 30264:de3275323dff
libqterminal: Avoid integer overflow in multiplication.
* libgui/qterminal/libqterminal/unix/BlockArray.cpp (moveBlock,
BlockArray::increaseBuffer): Cast integer offset argument of fseek to long int
before multiplication to avoid integer overflow. The overflow is very
unlikely to happen and this is adopted code (not actually maintained). But
it's an easy fix that doesn't clutter the code too much.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sun, 31 Oct 2021 18:06:22 +0100 |
parents | 48198770412e |
children | 3c60814448ea |
files | libgui/qterminal/libqterminal/unix/BlockArray.cpp |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/unix/BlockArray.cpp Sun Oct 31 17:13:01 2021 +0100 +++ b/libgui/qterminal/libqterminal/unix/BlockArray.cpp Sun Oct 31 18:06:22 2021 +0100 @@ -208,14 +208,14 @@ void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2) { - int res = fseek(fion, cursor * blocksize, SEEK_SET); + int res = fseek(fion, static_cast<long int> (cursor) * blocksize, SEEK_SET); if (res) perror("fseek"); res = fread(buffer2, blocksize, 1, fion); if (res != 1) perror("fread"); - res = fseek(fion, newpos * blocksize, SEEK_SET); + res = fseek(fion, static_cast<long int> (newpos) * blocksize, SEEK_SET); if (res) perror("fseek"); res = fwrite(buffer2, blocksize, 1, fion); @@ -304,7 +304,7 @@ { // free one block in chain int firstblock = (offset + i) % size; - res = fseek(fion, firstblock * blocksize, SEEK_SET); + res = fseek(fion, static_cast<long int> (firstblock) * blocksize, SEEK_SET); if (res) perror("fseek"); res = fread(buffer1, blocksize, 1, fion); @@ -317,7 +317,7 @@ newpos = (cursor - offset + size) % size; moveBlock(fion, cursor, newpos, buffer2); } - res = fseek(fion, i * blocksize, SEEK_SET); + res = fseek(fion, static_cast<long int> (i) * blocksize, SEEK_SET); if (res) perror("fseek"); res = fwrite(buffer1, blocksize, 1, fion);