All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] login-utils: use getdtablesize() correctly in login.c
@ 2012-04-20 14:58 chas williams - CONTRACTOR
  2012-04-23 12:02 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: chas williams - CONTRACTOR @ 2012-04-20 14:58 UTC (permalink / raw)
  To: util-linux

while it might seem harmless to close a non-existent descriptor, we have
a local configuration that protects a certain descriptor by lowering
rlim_cur to prevent child processes from closing said descriptor. this
descriptor points to a ticket cache which we need later for the user.

Author: chas williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
Date:   Fri Apr 20 10:49:51 2012 -0400

    login-utils: use getdtablesize() correctly in login.c
    
    getdtablesize() is the number of descriptors and since decriptors start
    at 0, its value isnt the largest descriptors possible.  One should use
    getdtablesize() - 1 instead.
    
    Signed-off-by: Chas Williams - CONTRACTOR <chas@cmf.nrl.navy.mil>

diff --git a/login-utils/login.c b/login-utils/login.c
index 6c3b6f7..026c72b 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -1290,7 +1290,7 @@ int main(int argc, char **argv)
 			*p++ = ' ';
 	}
 
-	for (cnt = getdtablesize(); cnt > 2; cnt--)
+	for (cnt = (getdtablesize() - 1); cnt > 2; cnt--)
 		close(cnt);
 
 	setpgrp();	 /* set pgid to pid this means that setsid() will fail */

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] login-utils: use getdtablesize() correctly in login.c
  2012-04-20 14:58 [PATCH] login-utils: use getdtablesize() correctly in login.c chas williams - CONTRACTOR
@ 2012-04-23 12:02 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2012-04-23 12:02 UTC (permalink / raw)
  To: chas williams - CONTRACTOR; +Cc: util-linux

On Fri, Apr 20, 2012 at 10:58:28AM -0400, chas williams - CONTRACTOR wrote:
>     login-utils: use getdtablesize() correctly in login.c
>     
>     getdtablesize() is the number of descriptors and since decriptors start
>     at 0, its value isnt the largest descriptors possible.  One should use
>     getdtablesize() - 1 instead.

 Applied, thanks.

 I have also added fallback for the getdtablesize() to lib/fileutils.c, it
 seems that the function is not too portable.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-23 12:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-20 14:58 [PATCH] login-utils: use getdtablesize() correctly in login.c chas williams - CONTRACTOR
2012-04-23 12:02 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.