Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   ArchLinux Pacman Development (http://www.linux-archive.org/archlinux-pacman-development/)
-   -   Avoid interger overflow when calculating remaining line length (http://www.linux-archive.org/archlinux-pacman-development/692956-avoid-interger-overflow-when-calculating-remaining-line-length.html)

Allan McRae 08-11-2012 01:48 PM

Avoid interger overflow when calculating remaining line length
 
When the len and cidx were changed to size_t in a8a1b093, it was
possible to have an integer overflow when a line ended right at the
edge of the terminal width.

Signed-off-by: Allan McRae <allan@archlinux.org>
---

Replicate with linux-lts-3.0.39-1 in the Arch Linux [core] repo and a terminal
with 80 width.

src/pacman/util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pacman/util.c b/src/pacman/util.c
index 7f7f6a7..995308c 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -296,7 +296,7 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols)
while(q < next) {
len += wcwidth(*q++);
}
- if(len > (cols - cidx - 1)) {
+ if((len + 1) > (cols - cidx)) {
/* wrap to a newline and reindent */
printf("
%-*s", (int)indent, "");
cidx = indent;
--
1.7.11.4


All times are GMT. The time now is 07:18 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.