From owner-svn-src-all@freebsd.org Sun Aug 16 13:59:12 2015 Return-Path: Delivered-To: svn-src-all@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 76E679BA675; Sun, 16 Aug 2015 13:59:12 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 600C6DCF; Sun, 16 Aug 2015 13:59:12 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7GDxCNs086946; Sun, 16 Aug 2015 13:59:12 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7GDxCwq086945; Sun, 16 Aug 2015 13:59:12 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201508161359.t7GDxCwq086945@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Sun, 16 Aug 2015 13:59:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r286827 - head/sys/teken X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Aug 2015 13:59:12 -0000 Author: ed Date: Sun Aug 16 13:59:11 2015 New Revision: 286827 URL: https://svnweb.freebsd.org/changeset/base/286827 Log: Pick UINT_MAX / 100 as an upperbound. The fix that I applied in r286798 is already good, but it assumes that sizeof(int) > sizeof(short). Express the upperbound in terms of UINT_MAX. By dividing that by 100, we're sure that the resulting value is never larger than approximately UINT_MAX / 10, which is safe. PR: 202326 Discussed with: kcwu csie org MFC after: 1 month Modified: head/sys/teken/teken.c Modified: head/sys/teken/teken.c ============================================================================== --- head/sys/teken/teken.c Sun Aug 16 12:57:17 2015 (r286826) +++ head/sys/teken/teken.c Sun Aug 16 13:59:11 2015 (r286827) @@ -411,13 +411,16 @@ teken_state_numbers(teken_t *t, teken_ch /* First digit. */ t->t_stateflags &= ~TS_FIRSTDIGIT; t->t_nums[t->t_curnum] = c - '0'; - } else if (t->t_nums[t->t_curnum] < USHRT_MAX) { + } else if (t->t_nums[t->t_curnum] < UINT_MAX / 100) { /* - * Screen positions are stored as unsigned - * shorts. There is no need to continue parsing - * input once the value exceeds USHRT_MAX. It - * would only allow for integer overflows when - * performing arithmetic on the cursor position. + * There is no need to continue parsing input + * once the value exceeds the size of the + * terminal. It would only allow for integer + * overflows when performing arithmetic on the + * cursor position. + * + * Ignore any further digits if the value is + * already UINT_MAX / 100. */ t->t_nums[t->t_curnum] = t->t_nums[t->t_curnum] * 10 + c - '0';