Eliminate several cases of multiplication in arguments to calloc
authorCarl Worth <cworth@cworth.org>
Wed, 3 Sep 2014 21:18:18 +0000 (14:18 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 4 Sep 2014 01:37:02 +0000 (18:37 -0700)
commitc35f14f36880eb20f5e54480444e343520e9bec5
tree860639f711be92e6ee031b005ac0284320c91d39
parent96ce065db46d11f5ad6423f4a522f3e92153b3cf
Eliminate several cases of multiplication in arguments to calloc

In commit 32f2fd1c5d6088692551c80352b7d6fa35b0cd09, several calls to
_mesa_calloc(x) were replaced with calls to calloc(1, x). This is strictly
equivalent to what the code was doing previously.

But for cases where "x" involves multiplication, now that we are explicitly
using the two-argument calloc, we can do one step better and replace:

calloc(1, A * B);

with:

calloc(A, B);

The advantage of the latter is that calloc will detect any overflow that would
have resulted from the multiplication and will fail the allocation, (whereas
the former would return a small allocation). So this fix can change
potentially exploitable buffer overruns into segmentation faults.

Reviewed-by: Matt Turner <mattst88@gmail.com>
src/gallium/drivers/freedreno/a2xx/ir-a2xx.c
src/gallium/drivers/freedreno/ir3/ir3.c
src/gallium/drivers/r600/r600_asm.c
src/mapi/glapi/gen/gl_gentable.py
src/mesa/drivers/dri/common/utils.c
src/mesa/drivers/dri/i965/brw_state_cache.c
src/mesa/main/atifragshader.c
src/mesa/program/prog_instruction.c
src/mesa/program/prog_optimize.c
src/mesa/program/prog_parameter.c
src/mesa/vbo/vbo_exec_array.c