aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-09-26 12:54:38 +0200
committerChristian Grothoff <christian@grothoff.org>2017-09-26 12:54:38 +0200
commit4a92d3943554681ce35e8106ef4f889c7a3bfed3 (patch)
tree26c5cf5d54904db0d30a2257f976595e05d3b5f7 /src
parentfce0277df0380f3758749c84222f0d76b612385b (diff)
downloadgnunet-4a92d3943554681ce35e8106ef4f889c7a3bfed3.tar.gz
gnunet-4a92d3943554681ce35e8106ef4f889c7a3bfed3.zip
fix integer overflow in cast to long for very large timeouts on 32-bit platforms
Diffstat (limited to 'src')
-rw-r--r--src/util/network.c16
-rw-r--r--src/util/scheduler.c18
2 files changed, 23 insertions, 11 deletions
diff --git a/src/util/network.c b/src/util/network.c
index 66a468e45..942288613 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -1793,10 +1793,18 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1793 _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), 1793 _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
1794 "select"); 1794 "select");
1795 } 1795 }
1796 tv.tv_sec = timeout.rel_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us; 1796 if (timeout.rel_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us > (unsigned long long) LONG_MAX)
1797 tv.tv_usec = 1797 {
1798 (timeout.rel_value_us - 1798 tv.tv_sec = LONG_MAX;
1799 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value_us)); 1799 tv.tv_usec = 999999L;
1800 }
1801 else
1802 {
1803 tv.tv_sec = (long) (timeout.rel_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us);
1804 tv.tv_usec =
1805 (timeout.rel_value_us -
1806 (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.rel_value_us));
1807 }
1800 return select (nfds, 1808 return select (nfds,
1801 (NULL != rfds) ? &rfds->sds : NULL, 1809 (NULL != rfds) ? &rfds->sds : NULL,
1802 (NULL != wfds) ? &wfds->sds : NULL, 1810 (NULL != wfds) ? &wfds->sds : NULL,
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index a7b1d8e2a..be5533050 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -73,7 +73,7 @@
73 * Argument to be passed from the driver to 73 * Argument to be passed from the driver to
74 * #GNUNET_SCHEDULER_run_from_driver(). Contains the 74 * #GNUNET_SCHEDULER_run_from_driver(). Contains the
75 * scheduler's internal state. 75 * scheduler's internal state.
76 */ 76 */
77struct GNUNET_SCHEDULER_Handle 77struct GNUNET_SCHEDULER_Handle
78{ 78{
79 /** 79 /**
@@ -94,7 +94,7 @@ struct GNUNET_SCHEDULER_Handle
94 * Driver we used for the event loop. 94 * Driver we used for the event loop.
95 */ 95 */
96 const struct GNUNET_SCHEDULER_Driver *driver; 96 const struct GNUNET_SCHEDULER_Driver *driver;
97 97
98}; 98};
99 99
100 100
@@ -127,7 +127,7 @@ struct GNUNET_SCHEDULER_Task
127 * Handle to the scheduler's state. 127 * Handle to the scheduler's state.
128 */ 128 */
129 const struct GNUNET_SCHEDULER_Handle *sh; 129 const struct GNUNET_SCHEDULER_Handle *sh;
130 130
131 /** 131 /**
132 * Set of file descriptors this task is waiting 132 * Set of file descriptors this task is waiting
133 * for for reading. Once ready, this is updated 133 * for for reading. Once ready, this is updated
@@ -172,7 +172,7 @@ struct GNUNET_SCHEDULER_Task
172 * Size of the @e fds array. 172 * Size of the @e fds array.
173 */ 173 */
174 unsigned int fds_len; 174 unsigned int fds_len;
175 175
176 /** 176 /**
177 * Why is the task ready? Set after task is added to ready queue. 177 * Why is the task ready? Set after task is added to ready queue.
178 * Initially set to zero. All reasons that have already been 178 * Initially set to zero. All reasons that have already been
@@ -1150,6 +1150,10 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1150 struct GNUNET_SCHEDULER_Task *pos; 1150 struct GNUNET_SCHEDULER_Task *pos;
1151 struct GNUNET_SCHEDULER_Task *prev; 1151 struct GNUNET_SCHEDULER_Task *prev;
1152 1152
1153 if (at.abs_value_us > UINT64_MAX / 10)
1154 {
1155 GNUNET_assert (0);
1156 }
1153 GNUNET_assert (NULL != active_task); 1157 GNUNET_assert (NULL != active_task);
1154 GNUNET_assert (NULL != task); 1158 GNUNET_assert (NULL != task);
1155 t = GNUNET_new (struct GNUNET_SCHEDULER_Task); 1159 t = GNUNET_new (struct GNUNET_SCHEDULER_Task);
@@ -1849,7 +1853,7 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1849 * 1853 *
1850 * @param sh scheduler handle that was given to the `loop` 1854 * @param sh scheduler handle that was given to the `loop`
1851 * @return #GNUNET_OK if there are more tasks that are ready, 1855 * @return #GNUNET_OK if there are more tasks that are ready,
1852 * and thus we would like to run more (yield to avoid 1856 * and thus we would like to run more (yield to avoid
1853 * blocking other activities for too long) 1857 * blocking other activities for too long)
1854 * #GNUNET_NO if we are done running tasks (yield to block) 1858 * #GNUNET_NO if we are done running tasks (yield to block)
1855 * #GNUNET_SYSERR on error 1859 * #GNUNET_SYSERR on error
@@ -1876,11 +1880,11 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1876 pending_timeout_last = NULL; 1880 pending_timeout_last = NULL;
1877 queue_ready_task (pos); 1881 queue_ready_task (pos);
1878 } 1882 }
1879 1883
1880 if (0 == ready_count) 1884 if (0 == ready_count)
1881 return GNUNET_NO; 1885 return GNUNET_NO;
1882 1886
1883 /* find out which task priority level we are going to 1887 /* find out which task priority level we are going to
1884 process this time */ 1888 process this time */
1885 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP; 1889 max_priority_added = GNUNET_SCHEDULER_PRIORITY_KEEP;
1886 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]); 1890 GNUNET_assert (NULL == ready_head[GNUNET_SCHEDULER_PRIORITY_KEEP]);