[pacman-dev] [PATCH] Avoid interger overflow when calculating remaining line length

Allan McRae allan at archlinux.org
Sat Aug 11 09:48:02 EDT 2012


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 at 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("\n%-*s", (int)indent, "");
 				cidx = indent;
-- 
1.7.11.4



More information about the pacman-dev mailing list