Commit c26f2521 authored by Paul Eggert's avatar Paul Eggert
Browse files

* xgselect.c (xg_select): Check for size calculation overflow.

Don't update size until alloc done.
parent c678c835
2011-07-29 Paul Eggert <eggert@cs.ucla.edu> 2011-07-29 Paul Eggert <eggert@cs.ucla.edu>
* xgselect.c (xg_select): Check for size calculation overflow.
Don't update size until alloc done.
* xfns.c: Integer and memory overflow fixes. * xfns.c: Integer and memory overflow fixes.
(x_encode_text, x_set_name_internal, Fx_change_window_property): (x_encode_text, x_set_name_internal, Fx_change_window_property):
Use ptrdiff_t, not int, to count sizes, since they can exceed Use ptrdiff_t, not int, to count sizes, since they can exceed
......
...@@ -54,10 +54,16 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds, ...@@ -54,10 +54,16 @@ xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
do { do {
if (n_gfds > gfds_size) if (n_gfds > gfds_size)
{ {
while (n_gfds > gfds_size) int gfds_size_max =
gfds_size *= 2; min (INT_MAX, min (PTRDIFF_MAX, SIZE_MAX) / sizeof *gfds);
int size;
if (gfds_size_max / 2 < n_gfds)
memory_full (SIZE_MAX);
size = 2 * n_gfds;
gfds_size = 0;
xfree (gfds); xfree (gfds);
gfds = xmalloc (sizeof (*gfds) * gfds_size); gfds = xmalloc (sizeof *gfds * size);
gfds_size = size;
} }
n_gfds = g_main_context_query (context, n_gfds = g_main_context_query (context,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment