From owner-svn-src-all@FreeBSD.ORG Thu Feb 12 21:07:43 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2B562EB9; Thu, 12 Feb 2015 21:07:43 +0000 (UTC) Received: from svn.freebsd.org (svn.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 1643AC5A; Thu, 12 Feb 2015 21:07:43 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1CL7gWs004042; Thu, 12 Feb 2015 21:07:42 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1CL7gaO004041; Thu, 12 Feb 2015 21:07:42 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201502122107.t1CL7gaO004041@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Thu, 12 Feb 2015 21:07:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r278634 - head/lib/libc/gen 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.18-1 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: Thu, 12 Feb 2015 21:07:43 -0000 Author: pfg Date: Thu Feb 12 21:07:42 2015 New Revision: 278634 URL: https://svnweb.freebsd.org/changeset/base/278634 Log: ulimit(3): Fix broken check. The existing implementation had a broken comparison that could overflow. Replace this with a check that avoids the overflow before it happens. Consistently return a maximum value also on the case of negative arguments since negative is considered an overflow and means infinity for our current setrlimit(). Discussed with: bde (rather extensively) CID: 1199295 MFC after: 1 week Modified: head/lib/libc/gen/ulimit.c Modified: head/lib/libc/gen/ulimit.c ============================================================================== --- head/lib/libc/gen/ulimit.c Thu Feb 12 20:57:57 2015 (r278633) +++ head/lib/libc/gen/ulimit.c Thu Feb 12 21:07:42 2015 (r278634) @@ -53,13 +53,13 @@ ulimit(int cmd, ...) va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); + if (arg > RLIM_INFINITY / 512 || arg < 0) + arg = RLIM_INFINITY / 512; limit.rlim_max = limit.rlim_cur = (rlim_t)arg * 512; /* The setrlimit() function sets errno to EPERM if needed. */ if (setrlimit(RLIMIT_FSIZE, &limit) == -1) return (-1); - if (arg * 512 > LONG_MAX) - return (LONG_MAX); return (arg); } else { errno = EINVAL;