Skip to content

Conversation

@chenshuo
Copy link

When running as root, chmod("/dev/null", 0644) will break most Unix-like
systems as "/dev/null" can't be open for write by non-root users anymore.

Before the fix:
root@linux# strace -f -e chmod ./netserver
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
strace: Process 976220 attached
[pid 976219] +++ exited with 0 +++
chmod("/dev/null", 0644) = 0

Fixes: 5380b1f ("netserver: use mkstemp to create/open debug file")

…fault).

When running as root, chmod("/dev/null", 0644) will break most Unix-like
systems as "/dev/null" can't be open for write by non-root users anymore.

Before the fix:
root@linux# strace -f -e chmod ./netserver
Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
strace: Process 976220 attached
[pid 976219] +++ exited with 0 +++
chmod("/dev/null", 0644)                = 0

Fixes: 5380b1f ("netserver: use mkstemp to create/open debug file")
Copy link

@jpbrucker jpbrucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as #27

I just ran into a related problem: when exiting netserver, we actually remove /dev/null!

if (buf.st_size == 0) unlink(FileName);

I noticed this when launching netserver from inetd as root, /dev/null just disappears after the first netperf run. Probably not a good idea to run as root, I fixed my config now but others will run into this. Would you like to fix that one as well or shall I send a fix? I don't mind either way, I could also fix both.


chmod(FileName,0644);
/* Only chmod() if FileName != "/dev/null" */
if (strcmp(FileName, NETPERF_NULL)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be simpler as `if (!suppress_debug)'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants