This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.
Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
The following program: #include <ulimit.h> #include <stdio.h> int main (void) { long int res = ulimit (2, -1); printf ("Res: %ld, errno: %m\n", res); return 0; } Returns: $ ./a.out Res: 0, errno: Success which is wrong, setting the limit to -1 should IMO give an error. The problem is that in ulimit.c we tread the second argument as long int and assign it to: limit.rlim_cur = newlimit * 512; where rlim_cur is of type rlim_t which is unsigned long. Shouldn't we check for negative values and set errno to EINVAL in this case? I'm appending a patch. Can somebody please double check this with the standards? If the patch is ok, I'll fix also the other ulimit implementations in glibc. Ok to commit? Andreas 2001-09-22 Andreas Jaeger <aj@suse.de> * sysdeps/unix/sysv/linux/ulimit.c (__ulimit): Return an error for negative values on UL_SETFSIZE. ============================================================ Index: sysdeps/unix/sysv/linux/ulimit.c --- sysdeps/unix/sysv/linux/ulimit.c 2001/07/06 04:56:13 1.8 +++ sysdeps/unix/sysv/linux/ulimit.c 2001/09/22 13:34:53 @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,92,94,95,96,97,98,2000 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,94,95,96,97,98,2000,2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -55,10 +55,15 @@ { long int newlimit = va_arg (va, long int); - limit.rlim_cur = newlimit * 512; - limit.rlim_max = newlimit * 512; - - result = __setrlimit (RLIMIT_FSIZE, &limit); + if (newlimit >= 0) + { + limit.rlim_cur = newlimit * 512; + limit.rlim_max = newlimit * 512; + + result = __setrlimit (RLIMIT_FSIZE, &limit); + } + else + __set_errno (EINVAL); } break; -- Andreas Jaeger SuSE Labs aj@suse.de private aj@arthur.inka.de http://www.suse.de/~aj
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |