| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DomainKey-Signature: | a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:from:to:subject:date:message-id:content-type | |
| :content-transfer-encoding:mime-version; q=dns; s=default; b=Ono | |
| kaAchQDXHFAbvxsUtpzua+2Cjgp6JF74sijbIDSNFtTcgZNlFEPn3wQJms6Zq+7W | |
| MDn4h2ugtJ4Sw6ONM8HOaXsGQwjjsKdafKkLDFN+BQ9st4pqP/hNH+nPDlP0/D1T | |
| 9PHvFPcTpxXZRLvzgL3wHZyKjzENjpMl3XAzsgwM= | |
| DKIM-Signature: | v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id |
| :list-unsubscribe:list-subscribe:list-archive:list-post | |
| :list-help:sender:from:to:subject:date:message-id:content-type | |
| :content-transfer-encoding:mime-version; s=default; bh=meRcD8P5c | |
| oD4ACC0RPMw875+kUY=; b=uTltP0VTjABiCEWTvbJu88DR5oTGo1+6c/pTj+PTN | |
| i13oac2TFt1gF5DAPvDrdSwMOSAZJRNLh7eygI6TRdtF5XZSN3vpx//mKQ0z9WAV | |
| o78ALbuthN8onlpaKAXKvb2HR7Avo3GTx3qg/plLKJ5G/SHeQKinkFnlr2erzSxT | |
| dE= | |
| Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
| List-Id: | <cygwin.cygwin.com> |
| List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
| List-Archive: | <http://sourceware.org/ml/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
| Sender: | cygwin-owner AT cygwin DOT com |
| Mail-Followup-To: | cygwin AT cygwin DOT com |
| Delivered-To: | mailing list cygwin AT cygwin DOT com |
| X-Spam-SWARE-Status: | No, score=-4.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_MED,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.1 |
| X-IronPortListener: | Outbound_SMTP |
| X-IronPort-Anti-Spam-Filtered: | true |
| X-IronPort-Anti-Spam-Result: | AucFAENagVGcKEeo/2dsb2JhbABSgwc3vx18Fm0HgiEBBBIVE1EBFRUULxMmAQQbGodqn22ET5pBjnGDKWEDjhqKNYURinqDDYIn |
| From: | "Lavrentiev, Anton (NIH/NLM/NCBI) [C]" <lavr AT ncbi DOT nlm DOT nih DOT gov> |
| To: | "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com> |
| Subject: | setrlimit() does not check for excess "cur" values |
| Date: | Wed, 1 May 2013 18:14:47 +0000 |
| Message-ID: | <5F8AAC04F9616747BC4CC0E803D5907D0AF74D33@MLBXv04.nih.gov> |
| MIME-Version: | 1.0 |
| X-MIME-Autoconverted: | from quoted-printable to 8bit by delorie.com id r41IFNZQ010358 |
Hi,
It looks like Cygwin's implementation of setrlimit() does not check
whether a "cur" value being set for a resource has been requested
higher than the "max" value. It should have returned EINVAL.
From the documentation (Linux):
EINVAL resource is not valid; or, for setrlimit(): rlim->rlim_cur was greater than rlim->rlim_max.
Also noted for Linux in the "BUGS" section:
Kernels before 2.4.22 did not diagnose the error EINVAL for setrlimit() when rlim->rlim_cur was greater than rlim->rlim_max.
Test case:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
int main(void)
{
struct rlimit rl;
memset(&rl, 0, sizeof(rl));
rl.rlim_cur = 10;
rl.rlim_max = 1;
if (setrlimit(RLIMIT_CORE, &rl) != 0)
perror("RLIMIT_CORE");
rl.rlim_cur = RLIM_INFINITY;
if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
perror("RLIMIT_NOFILE");
return 0;
}
Compilation:
gcc -Wall test.c
Execution in Cygwin:
> ./a.exe
(no output)
Execution on Linux:
> ./a.out
RLIMIT_CORE: Invalid argument
RLIMIT_NOFILE: Invalid argument
The following patch is suggested for cygwin/resource.cc:
*** resource.cc Wed May 1 14:10:28 2013
--- resource.cc.orig Mon Apr 8 21:04:52 2013
*************** setrlimit (int resource, const struct rl
*** 173,181 ****
if (getrlimit (resource, &oldlimits) < 0)
return -1;
! if (rlp->rlim_cur > rlp->rlim_max)
! resource = RLIMIT_NLIMITS; // Catch default below, EINVAL
! else if (oldlimits.rlim_cur == rlp->rlim_cur &&
oldlimits.rlim_max == rlp->rlim_max)
// No change in resource requirements, succeed immediately
return 0;
--- 173,179 ----
if (getrlimit (resource, &oldlimits) < 0)
return -1;
! if (oldlimits.rlim_cur == rlp->rlim_cur &&
oldlimits.rlim_max == rlp->rlim_max)
// No change in resource requirements, succeed immediately
return 0;
TIA,
Anton Lavrentiev
Contractor NIH/NLM/NCBI
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |