Bug 2914 - gethostid don't check if file exist before tryng to use it
Summary: gethostid don't check if file exist before tryng to use it
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.3
: P3 enhancement
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-13 12:42 UTC by Julien Dumont
Modified: 2015-01-29 13:35 UTC (History)
1 user (show)

See Also:
Host: i686
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
sample for reproduct (184 bytes, application/octet-stream)
2006-07-13 12:44 UTC, Julien Dumont
Details
patch for fedora core 3 SRPMS glibc-2.3.3-74.src.rpm (690 bytes, application/octet-stream)
2006-07-13 12:46 UTC, Julien Dumont
Details
patch for generic GNU glibc 2.3 (409 bytes, application/octet-stream)
2006-07-13 12:48 UTC, Julien Dumont
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Dumont 2006-07-13 12:42:04 UTC
using gethostid() function provide by glibc trying to open twice a file which
don't exist. 

strace output concerning this function. 

open("/etc/hostid", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
open("/etc/hostid", O_RDONLY|O_LARGEFILE) = -1 ENOENT (No such file or directory)
Comment 1 Julien Dumont 2006-07-13 12:44:19 UTC
Created attachment 1158 [details]
sample for reproduct

hostid.c is an example for reproduct.
Comment 2 Julien Dumont 2006-07-13 12:46:49 UTC
Created attachment 1159 [details]
patch for fedora core 3 SRPMS glibc-2.3.3-74.src.rpm 

patch for fedora core 3 SRPMS glibc-2.3.3-74.src.rpm
Comment 3 Julien Dumont 2006-07-13 12:48:41 UTC
Created attachment 1160 [details]
patch for generic GNU glibc 2.3

patch for generic GNU glibc 2.3
Comment 4 Julien Dumont 2006-07-13 12:50:45 UTC
This exist also on glibc 2.4 and the patch is the same. ( use stat )
Comment 5 Ulrich Drepper 2006-08-03 08:51:31 UTC
I've changed this is CVS.  The patch isn't OK.  There is no need for the stat
because a) it's not really much faster than the open and b) if somebody uses
gethostid there better be such a file.  The real problem was that the patch
introducing the OLD_HOSTIDFILE macro contained  abug.  This is now fixed.
Comment 6 Julien Dumont 2006-08-03 20:15:18 UTC
Thanks for this ;)

I'm agree with you about open and stat and their performance on local filesystem.
But It seems thant it's not the case over Network filesystem or Virtual filesystem.

Sure isn't a good idea to have /etc/ over VFS or NFS, but in this case it seems
than using 'open' have mores 'impact' than using only stat. Performance be
better and we don't have problem with concurent remote access.
 

But in fact is it true or it's just my feelings ?

Julien