From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RDNS_NONE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: from authenticated user by zero.zsh.org with local id 1kiiQ6-000JSq-8w; Fri, 27 Nov 2020 18:24:34 +0000 Authentication-Results: zsh.org; iprev=pass (rcpt-expgw.biglobe.ne.jp) smtp.remote-ip=133.208.98.2; dmarc=none header.from=kba.biglobe.ne.jp; arc=none Received: from rcpt-expgw.biglobe.ne.jp ([133.208.98.2]:53186) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1kiiPj-000JE6-8l; Fri, 27 Nov 2020 18:24:13 +0000 Received: from vc-gw.biglobe.ne.jp by rcpt-expgw.biglobe.ne.jp (hngd/4514161018) with ESMTP id 0ARIO5rx006089 for ; Sat, 28 Nov 2020 03:24:05 +0900 Received: from smtp-gw.biglobe.ne.jp ([192.168.154.157]) by vc-gw.biglobe.ne.jp (shby/1011270619) with ESMTP id 0ARIO5sq016640 for ; Sat, 28 Nov 2020 03:24:05 +0900 X-Biglobe-Sender: Received: from [192.168.0.23] ([14.9.102.64]) by smtp-gw.biglobe.ne.jp id D607C0A89941; Sat, 28 Nov 2020 03:24:05 +0900 (JST) From: "Jun. T" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Subject: Re: [PATCHv1] [long] improvements to limit/ulimit API and doc Date: Sat, 28 Nov 2020 03:24:04 +0900 References: <20201123214942.hi2rx7n3jk25ucmd@chazelas.org> <37CA6007-8692-4F71-90BF-80C422BE21E3@kba.biglobe.ne.jp> <20201126135523.7daayb7l543yrmcj@chazelas.org> <05C414E9-A152-40CD-90C3-C74D7FD773A8@kba.biglobe.ne.jp> <20201126172354.g5guqrhu3mwrv6ia@chazelas.org> To: zsh-workers@zsh.org In-Reply-To: <20201126172354.g5guqrhu3mwrv6ia@chazelas.org> Message-Id: X-Mailer: Apple Mail (2.3445.104.17) X-Biglobe-Spnum: 26852 X-Seq: 47667 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: > 2020/11/27 2:23, Stephane Chazelas wrote: >=20 > 2020-11-27 00:22:05 +0900, Jun. T: >=20 >> Zsh only need to check whether the new limit user wants to set is >> within the range of rlim_t. >=20 > Yes, but how do you determine that range? Should we not also > reject 18446744073709551615 as out-of-range on systems where > it's RLIM_INFINITY since it's not preventing file sizes to get > past 18446744073709551615 for instance. I guess you mean we should reject RLIM_INFINITY, and yes I agree with = it. How about the patch below (to your v2)? # Even if you accept this patch, maybe better to commit it separately = after # your patch (which may be separated into parts) for finer granularity. Jun diff --git a/Src/Builtins/rlimits.c b/Src/Builtins/rlimits.c index b6568d956..69174fe8e 100644 --- a/Src/Builtins/rlimits.c +++ b/Src/Builtins/rlimits.c @@ -297,7 +297,7 @@ printrlim(rlim_t val, const char *unit) static rlim_t zstrtorlimt(const char *s, int lim, int ulimit, char **err) { - rlim_t ret =3D 0; + rlim_t ret =3D 0, tmp; const char *orig =3D s; enum zlimtype type =3D resinfo[lim]->type; *err =3D NULL; @@ -305,8 +305,14 @@ zstrtorlimt(const char *s, int lim, int ulimit, = char **err) if (strcmp(s, "unlimited") =3D=3D 0) return RLIM_INFINITY; =20 - for (; *s >=3D '0' && *s <=3D '9'; s++) - ret =3D ret * 10 + *s - '0'; + for (; *s >=3D '0' && *s <=3D '9'; s++) { + if ((tmp =3D ret * 10 + *s - '0') < ret) { + *err =3D "limit out of range"; + return 0; + } + else + ret =3D tmp; + } =20 if (s =3D=3D orig) { *err =3D "decimal integer expected"; @@ -412,6 +418,7 @@ zstrtorlimt(const char *s, int lim, int ulimit, char = **err) /* * memory-type resource */ + rlim_t unit =3D 1; if (*s) { if (*s =3D=3D 'b' || *s =3D=3D 'B') s++; @@ -425,7 +432,7 @@ zstrtorlimt(const char *s, int lim, int ulimit, char = **err) /* KB =3D=3D 1000 */ const char *p; for (p =3D suffix; p <=3D offset; p +=3D 2) - ret *=3D 1000; + unit *=3D 1000; s++; } else { @@ -433,7 +440,7 @@ zstrtorlimt(const char *s, int lim, int ulimit, char = **err) if ((s[0] =3D=3D 'i' || s[0] =3D=3D 'I') && (s[1] =3D=3D 'b' || s[1] =3D=3D 'B')) s +=3D 2; - ret <<=3D ((offset - suffix) / 2 + 1) * 10; + unit <<=3D ((offset - suffix) / 2 + 1) * 10; } } } @@ -444,7 +451,7 @@ zstrtorlimt(const char *s, int lim, int ulimit, char = **err) } else { if (ulimit) - ret *=3D resinfo[lim]->unit; + unit =3D resinfo[lim]->unit; else #ifdef HAVE_RLIMIT_MSGQUEUE if (lim !=3D RLIMIT_MSGQUEUE) @@ -462,8 +469,19 @@ zstrtorlimt(const char *s, int lim, int ulimit, = char **err) * compatibility with tcsh. */ #endif - ret *=3D 1024; + unit =3D 1024; } + if ((tmp =3D ret*unit) < ret) { + *err =3D "limit out of range"; + return 0; + } + else + ret =3D tmp; + } + if (ret =3D=3D RLIM_INFINITY) { + /* RLIM_INFINITY can be specified only by the string "unlimited" = */ + *err =3D "limit out of range"; + return 0; } return ret; }