Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netserver: do not chmod("/dev/null", 0644) when suppress_debug==1 #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@@ -260,7 +260,10 @@ open_debug_file()

#if !defined(WIN32)

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