Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Apr 2000 02:06:54 -0700 (PDT)
From:      jdg@debian.org
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/17824: [PATCH] /usr/bin/column has arithmetic overflows
Message-ID:  <200004060906.CAA43220@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         17824
>Category:       bin
>Synopsis:       [PATCH] /usr/bin/column has arithmetic overflows
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr  6 02:10:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Julian Gilbey
>Release:        I'm not (but it's still a bug in latest CVS)
>Organization:
>Environment:
N/A
>Description:
I discovered that column gave divide-by-zero errors in certain
situations (specifically, if the number of display columns is c and
the widest item of data has width w, then letting w8 = 8*((w+8)/8)
(rounding down to the nearest int), the error will occur if w<c<w8).
The patch in the "Fix" section below corrects this bug.  (It's not
obvious because usually c=80, so we cannot have w<c<w8.)

>How-To-Repeat:
polya:~ $ cat > /tmp/72
123456789012345678901234567890123456789012345678901234567890123456789012
polya:~ $ column -c 79 </tmp/72
Floating point exception
polya:~ $ 

>Fix:
[This patch won't work directly because of tab->space conversion.]

--- column.c.orig       Thu Mar 25 02:47:47 1999
+++ column.c    Wed Apr  5 23:42:31 2000
@@ -145,6 +145,10 @@

        maxlength = (maxlength + TAB) & ~(TAB - 1);
        numcols = termwidth / maxlength;
+       if (!numcols) {
+               print();
+               exit(eval);
+       }
        endcol = maxlength;
        for (chcnt = col = 0, lp = list;; ++lp) {
                chcnt += printf("%s", *lp);
@@ -173,6 +177,10 @@

        maxlength = (maxlength + TAB) & ~(TAB - 1);
        numcols = termwidth / maxlength;
+       if (!numcols) {
+               print();
+               exit(eval);
+       }
        numrows = entries / numcols;
        if (entries % numcols)
                ++numrows;


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200004060906.CAA43220>