-
Notifications
You must be signed in to change notification settings - Fork 852
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
Initialize tzcode early #1084
Initialize tzcode early #1084
Conversation
If there's a problem, can you give an example of how to reproduce it? |
|
I didn't say “define (Strictly speaking, the directory doesn't have to be empty to demonstrate the problem; it just has to not contain |
Ok, thanks. |
I suggest adding a comment, as in your commit body, with this patch: diff --git a/tcpdump.c b/tcpdump.c
index b7eaad14d..19cdd1ab4 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1550,6 +1550,11 @@ main(int argc, char **argv)
if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0)
error("%s", ebuf);
+ /*
+ * An explicit tzset() call is usually not needed as it happens
+ * implicitly the first time we call localtime() or mktime(),
+ * but in some cases (sandboxing, chroot) this may be too late.
+ */
tzset();
while ( |
It seems that in the chroot case, |
+1 - if it wasn't obvious to whoever put in the chroot code and the Capsicum code, there might be others to whom it wasn't obvious. (In a better world, there would be ways in which a program running with no elevated privileges could capture traffic via, for example, libpcap running/opening a UNIX-domain socket to/etc. a program running with sufficient privileges to open {a BPF device, a PF_SOCKET socket, etc.} and be handed back a suitably-protected FD if, by some mechanism, the process making the request is deemed worthy of that privilege. That requires, of course, a way to determine what renders the process worthy. Process credentials? Some extended attribute that can only be set by somebody granted some privilege? Signed code? Signed code plus some form of extended attribute granting that privilege? That's sort of how Npcap works if you install it in "admin permissions required" mode; it runs a helper program, with a UAC prompt involved in the process of that helper program ending up with admin permissions, and the helper program uses the Windows "hand this process a HANDLE" API. Wireshark's use of a separate process to do the capturing gets you some of this, at the expense of the arm's-length relationship between the Wireshark/TShark process and dumpcap making some things awkward.) |
An explicit tzset() call is usually not needed as it happens implicitly the first time we call localtime() or mktime(), but in some cases (sandboxing, chroot) this may be too late.
05ac1d6
to
5c1ecd8
Compare
There is an answer here: Is it the same with Capsicum? |
The comment should perhaps be updated with: diff --git a/tcpdump.c b/tcpdump.c
index 19cdd1ab4..fef702991 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1554,6 +1554,8 @@ main(int argc, char **argv)
* An explicit tzset() call is usually not needed as it happens
* implicitly the first time we call localtime() or mktime(),
* but in some cases (sandboxing, chroot) this may be too late.
+ * In these cases, you need to set the TZ environment variable
+ * even if you have a valid /etc/localtime.
*/
tzset();
|
No, because it's not true. |
Could you explain? |
If that is true (which I doubt but will not be able to investigate closer until next week) then that's a bug in Debian that needs to be fixed there, rather than enshrined here. |
So do you mean that, if you call If so, is there also a valid /etc/localtime in the chrooted environment? |
Yes.
No. |
I suspect that's the problem. As per the bug comment you cited, POSIX specifies that some functions, such as
so you need the /etc/localtime link in the chrooted environment. A hard link to the appropriate file should exist even if the paths to the tz database files aren't accessible from the chrooted environment; a symbolic link would require that the files be present in the chrooted environment. |
Having some problems to do a hard link ("Operation not permitted") perhaps because |
Adding the |
The comment should perhaps be updated with: diff --git a/tcpdump.c b/tcpdump.c
index 19cdd1ab4..b39c25682 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1554,6 +1554,10 @@ main(int argc, char **argv)
* An explicit tzset() call is usually not needed as it happens
* implicitly the first time we call localtime() or mktime(),
* but in some cases (sandboxing, chroot) this may be too late.
+ * In the chroot case, at least with a glibc build, if
+ * /etc/localtime (and eventually the file to which it is linked)
+ * don't exist in the chroot directory to give a valid timezone data,
+ * you need to set the TZ environment variable.
*/
tzset();
|
Is that really the place for this information? It is neither specific to tcpdump nor universally applicable to the platforms it supports, and may very well be overcome by events in the near future. |
We need to document what has been fixed in the current state (and in the commit message), like: diff --git a/tcpdump.c b/tcpdump.c
index 19cdd1ab4..1d7f60272 100644
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1554,6 +1554,8 @@ main(int argc, char **argv)
* An explicit tzset() call is usually not needed as it happens
* implicitly the first time we call localtime() or mktime(),
* but in some cases (sandboxing, chroot) this may be too late.
+ * This fixes the Capsicum case and the TZ chroot case on glibc
+ * systems.
*/
tzset();
|
Thanks. |
An explicit
tzset()
call is usually not needed as it happens implicitly the first time we calllocaltime()
ormktime()
, but in some cases (sandboxing, chroot) this may be too late.