From owner-freebsd-hackers@freebsd.org Wed Jun 15 20:59:20 2016 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9586AA479FA for ; Wed, 15 Jun 2016 20:59:20 +0000 (UTC) (envelope-from er.abhinav.upadhyay@gmail.com) Received: from mail-oi0-x235.google.com (mail-oi0-x235.google.com [IPv6:2607:f8b0:4003:c06::235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 54CC0166C for ; Wed, 15 Jun 2016 20:59:20 +0000 (UTC) (envelope-from er.abhinav.upadhyay@gmail.com) Received: by mail-oi0-x235.google.com with SMTP id p204so39142201oih.3 for ; Wed, 15 Jun 2016 13:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=GLRL7F2LNAUQRaCGaoMGIwVCDt3AE4nOOv8GVVOCues=; b=rovFDV2eQnyfBO7muTz6KMI94i6/3vzj4kPX0ryb4pUork2fPek39jtvpaZSyKZ5fq 5vwxiHoBDXEIeJPdwMss3RDYcf9XcNG6xxZP12YCEiMwG7fwLkQNZCoIIOyp+Ac7y0mY vQopURu4mAcCZp0NkZtaOzE1wtuX1MsoFLdGIBfbxUNpgJitpLYH4onRMnEZgrdbv0bp sWXAoQK/4/i5/BtwbcaBqP5BbXddRtYAAGuGKYV+dVybw+bNnVA5zrs18XKs3Zq6v3uc vh/ImZE9s5RTHJDva8yVx6A+LRTE0x+qWifI3/erDLShSx13nMp+8ExOhCz73jtWG2E0 944Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=GLRL7F2LNAUQRaCGaoMGIwVCDt3AE4nOOv8GVVOCues=; b=XkcZpmlB4lwyiKboaXex9ZlsVdtX4vQUoxyrRcvmPJ99UXlT4bVJu6gG9bb2znbXHd D+TuKnNSVhHZddCA8MIIPwUgwykp0gqeU/SPg8AVK/YygSm6KX3Ghkmgbt2TQ4lCx1RT vas+gmWE9/RKkZnEiKC3qIuEK75M0TNRDf5BdMh7RtQvcHwtiTzusApWNRck5DSWymAb ksaRWXNRsgtXNVtLM6bQl+j5ptmw8WijNnEVkil2KG6F3WY7nO1vdO5h/p85g+inrGR2 7O1lFNY9EcEeuDJoQfCw9VXHCgc6lMuHU/RYpsViKeU4snzwgh8CF9arruQkWfxZCpcw nsvg== X-Gm-Message-State: ALyK8tJNy3YgUiwtAiFY+h1LBvvuDJXJq1KQ4Uh/0s+P5t9nDToyq1NFkC7kMo46MvkiKohM6xG6Pyqo6kB+hQ== X-Received: by 10.157.15.151 with SMTP id d23mr486637otd.49.1466024359671; Wed, 15 Jun 2016 13:59:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.157.57.199 with HTTP; Wed, 15 Jun 2016 13:59:19 -0700 (PDT) From: Abhinav Upadhyay Date: Thu, 16 Jun 2016 02:29:19 +0530 Message-ID: Subject: Possible bug in ul(1) To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Mailman-Approved-At: Wed, 15 Jun 2016 22:05:10 +0000 X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jun 2016 20:59:20 -0000 Hi, NetBSD's ul(1) had a bug, where it would dump core for certain inputs containing really long lines. For example, we had two man pages for which it would crash: man evrpc | ul man xdm | ul We had a statically allocated buffer (struct CHAR obuf[MAXBUF]) for representing columns in the lines of the input file, and for really long lines, we would try to read beyond the size of the buffer and crash. We've fixed it by using reallocarr(3) and friends [1]. FreeBSD also uses a statically allocated buffer, but it ensures that it never reads beyond the fixed size of the buffer and therefore doesn't crash for such bad inputs. line 170: while ((c = getwc(f)) != WEOF && col < MAXBUF) switch(c) { However, it stops reading the file just at the point where the number of columns in the line exceeds the buffer size and exits with status 0. I think, if it is not going to read the complete file, it should exit with a non-0 status, so that the user gets to know that the output from ul(1) is not complete? Or, probably it would be better to fix ul(1) so that it is able to read files with arbitrarily long lines. :) PS: I'm not subscribed to the list, so please keep me CC'ed. [1]: http://cvsweb.netbsd.org/bsdweb.cgi/src/usr.bin/ul/ul.c.diff?r1=1.16&r2=1.17&only_with_tag=MAIN - Abhinav