Fix crash due to invalid timespec given to pselect
authorIvan Delalande <colona@ycc.fr>
Fri, 12 Dec 2014 07:39:07 +0000 (08:39 +0100)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Tue, 23 Dec 2014 15:20:59 +0000 (16:20 +0100)
If blinktimeout is set to a value greater than 1000, pselect will
receive a timeout argument with tv_nsec greater than 1E9 (1 sec), and
fail, making st crash. This patch just ensures that the timespec
structure is correctly filled with a value properly decomposed between
tv_sec and tv_nsec.

Reported by JasonWoof on IRC. Thanks!

st.c

diff --git a/st.c b/st.c
index fc91334..db9a332 100644 (file)
--- a/st.c
+++ b/st.c
@@ -3922,6 +3922,9 @@ run(void) {
                                                        TIMEDIFF(now,
                                                                lastblink)));
                                        }
+                                       drawtimeout.tv_sec = \
+                                           drawtimeout.tv_nsec / 1E9;
+                                       drawtimeout.tv_nsec %= (long)1E9;
                                } else {
                                        tv = NULL;
                                }