[PATCH 00/17] Improved overflow checking for memory allocations

Alan Coopersmith alan.coopersmith at oracle.com
Tue Mar 31 17:50:13 PDT 2015


This series of patches borrows the reallocarray() interface from OpenBSD,
improves our xcalloc interfaces, and generally cleans up our array memory
allocation code to check calculations for memory allocations do not have
integer overflows in several more places than we previously checked.

Most of these probably couldn't overflow before, but now we can be sure
without having to do tedious manual analysis of each one, and without
giving the compiler a reason to assume that we must not have overflowed,
and thus optimize out any overflow checks that may have been in the wrong
order previously.

Alan Coopersmith (17):
  Remove remaining doc references to Xalloc, Xrealloc, and Xfree
  Let calloc handle multiplication
  Add XNFcallocarray() to allow xnfcalloc() to check for overflow
  Import reallocarray() from OpenBSD
  Add xallocarray() helper macro
  Add no-fail equivalents of allocarray & reallocarray
  Convert os/* to new *allocarray functions
  Convert dix/* to new *allocarray functions
  Convert top level extensions to new *allocarray functions
  Convert XKB to new *allocarray functions
  Convert exa & fb to new *allocarray functions
  Convert mi & miext to new *allocarray functions
  Convert glamor & glx to new *allocarray functions
  Convert hw/xfree86 to new *allocarray functions
  Convert hw/xnest & hw/vfb to new *allocarray functions
  Convert hw/kdrive to new *allocarray functions
  Convert hw/dmx to new *allocarray functions

 Xext/hashtable.c                        |    4 +-
 Xext/panoramiX.c                        |   10 ++--
 Xext/panoramiXprocs.c                   |   21 ++++-----
 Xext/saver.c                            |    2 +-
 Xext/shape.c                            |    2 +-
 Xext/sync.c                             |    4 +-
 Xext/xcmisc.c                           |    2 +-
 Xext/xf86bigfont.c                      |    4 +-
 Xext/xres.c                             |    2 +-
 Xext/xselinux_label.c                   |    2 +-
 Xext/xvmain.c                           |    2 +-
 Xi/exevents.c                           |    6 +--
 Xi/getprop.c                            |    2 +-
 Xi/xiproperty.c                         |    8 ++--
 Xi/xiquerypointer.c                     |    4 +-
 composite/compinit.c                    |    8 ++--
 config/config.c                         |    3 +-
 configure.ac                            |    2 +-
 dbe/dbe.c                               |   14 +++---
 dbe/midbe.c                             |    2 +-
 dix/atom.c                              |    4 +-
 dix/colormap.c                          |   71 ++++++++++++++---------------
 dix/devices.c                           |    4 +-
 dix/dispatch.c                          |   10 ++--
 dix/dixfonts.c                          |   18 ++++----
 dix/enterleave.c                        |    2 +-
 dix/events.c                            |    4 +-
 dix/extension.c                         |    6 +--
 dix/glyphcurs.c                         |    4 +-
 dix/grabs.c                             |    8 ++--
 dix/property.c                          |   10 ++--
 dix/region.c                            |    2 +-
 dix/resource.c                          |    6 +--
 dix/touch.c                             |    8 ++--
 doc/Xserver-spec.xml                    |    9 ++--
 exa/exa_accel.c                         |    8 ++--
 exa/exa_glyphs.c                        |    4 +-
 exa/exa_migration_mixed.c               |    4 +-
 fb/fbcopy.c                             |    2 +-
 fb/fbpict.c                             |    2 +-
 glamor/glamor_compositerects.c          |    2 +-
 glamor/glamor_glyphs.c                  |    2 +-
 glamor/glamor_gradient.c                |    8 ++--
 glamor/glamor_pixmap.c                  |    4 +-
 glamor/glamor_prepare.c                 |    4 +-
 glamor/glamor_utils.c                   |    2 +-
 glx/single2.c                           |    9 ++--
 glx/single2swap.c                       |    9 ++--
 hw/dmx/config/dmxconfig.c               |   10 ++--
 hw/dmx/dmx.c                            |   10 ++--
 hw/dmx/dmxcmap.c                        |    2 +-
 hw/dmx/dmxcursor.c                      |    2 +-
 hw/dmx/dmxextension.c                   |    4 +-
 hw/dmx/dmxfont.c                        |    6 +--
 hw/dmx/dmxgc.c                          |    2 +-
 hw/dmx/dmxinit.c                        |    4 +-
 hw/dmx/dmxpict.c                        |   10 ++--
 hw/dmx/dmxprop.c                        |    2 +-
 hw/dmx/dmxwindow.c                      |    4 +-
 hw/dmx/glxProxy/glxcmds.c               |   34 ++++++--------
 hw/dmx/glxProxy/glxscreens.c            |    9 ++--
 hw/dmx/input/dmxarg.c                   |    2 +-
 hw/dmx/input/dmxinputinit.c             |    4 +-
 hw/dmx/input/dmxmotion.c                |    5 +-
 hw/kdrive/ephyr/ephyrdriext.c           |    4 +-
 hw/kdrive/ephyr/hostx.c                 |   14 +++---
 hw/kdrive/fake/fake.c                   |    2 +-
 hw/kdrive/fbdev/fbdev.c                 |    2 +-
 hw/kdrive/src/kshadow.c                 |    2 +-
 hw/kdrive/src/kxv.c                     |    4 +-
 hw/vfb/InitOutput.c                     |    8 ++--
 hw/xfree86/common/xf86AutoConfig.c      |    2 +-
 hw/xfree86/common/xf86Bus.c             |   23 +++++-----
 hw/xfree86/common/xf86Config.c          |   22 ++++-----
 hw/xfree86/common/xf86Configure.c       |    6 +--
 hw/xfree86/common/xf86DGA.c             |    2 +-
 hw/xfree86/common/xf86Helper.c          |   32 +++++++------
 hw/xfree86/common/xf86Xinput.c          |    5 +-
 hw/xfree86/common/xf86cmap.c            |    6 +--
 hw/xfree86/common/xf86fbman.c           |   11 +++--
 hw/xfree86/common/xf86pciBus.c          |   10 ++--
 hw/xfree86/common/xf86platformBus.c     |    6 +--
 hw/xfree86/common/xf86sbusBus.c         |   10 ++--
 hw/xfree86/common/xf86vmode.c           |    8 ++--
 hw/xfree86/common/xf86xv.c              |   10 ++--
 hw/xfree86/common/xf86xvmc.c            |    2 +-
 hw/xfree86/ddc/ddc.c                    |    2 +-
 hw/xfree86/dri/xf86dri.c                |    2 +-
 hw/xfree86/dri2/dri2.c                  |    4 +-
 hw/xfree86/drivers/modesetting/driver.c |    2 +-
 hw/xfree86/i2c/xf86i2c.c                |    2 +-
 hw/xfree86/loader/loadmod.c             |   10 ++--
 hw/xfree86/modes/xf86Crtc.c             |   21 +++++----
 hw/xfree86/modes/xf86DiDGA.c            |    2 +-
 hw/xfree86/modes/xf86RandR12.c          |   20 ++++----
 hw/xfree86/os-support/bus/Sbus.c        |    2 +-
 hw/xfree86/utils/cvt/cvt.c              |    4 +-
 hw/xfree86/vbe/vbe.c                    |    4 +-
 hw/xnest/Color.c                        |   17 +++----
 hw/xnest/Display.c                      |    4 +-
 hw/xnest/GC.c                           |    5 +-
 hw/xnest/Keyboard.c                     |    2 +-
 hw/xnest/Screen.c                       |    4 +-
 include/dix-config.h.in                 |    3 ++
 include/os.h                            |   31 +++++++++++--
 include/xorg-server.h.in                |    3 ++
 mi/miarc.c                              |   25 +++++-----
 mi/mibitblt.c                           |   16 +++----
 mi/micmap.c                             |    8 ++--
 mi/micopy.c                             |    4 +-
 mi/miexpose.c                           |    2 +-
 mi/mifillrct.c                          |    4 +-
 mi/miglblt.c                            |    2 +-
 mi/miinitext.c                          |    4 +-
 mi/mipoly.c                             |    4 +-
 mi/mipolypnt.c                          |    2 +-
 mi/mipolyrect.c                         |    2 +-
 mi/miwideline.c                         |   42 ++++++++---------
 mi/miwindow.c                           |    6 +--
 mi/mizerarc.c                           |    4 +-
 mi/mizerline.c                          |    4 +-
 miext/damage/damage.c                   |    2 +-
 miext/rootless/rootlessWindow.c         |    4 +-
 miext/shadow/shalloc.c                  |    2 +-
 os/connection.c                         |   13 +++---
 os/reallocarray.c                       |   43 +++++++++++++++++
 os/utils.c                              |   24 +++++++++-
 pseudoramiX/pseudoramiX.c               |    6 +--
 randr/rrcrtc.c                          |   14 +++---
 randr/rrinfo.c                          |   10 ++--
 randr/rrmode.c                          |    4 +-
 randr/rroutput.c                        |   14 +++---
 randr/rrproperty.c                      |   12 ++---
 randr/rrproviderproperty.c              |    6 +--
 randr/rrtransform.c                     |    2 +-
 record/record.c                         |   35 +++++++-------
 record/set.c                            |    4 +-
 render/filter.c                         |   12 ++---
 render/miindex.c                        |    2 +-
 render/mipict.c                         |    4 +-
 render/picture.c                        |    2 +-
 render/render.c                         |    6 +--
 xfixes/region.c                         |    2 +-
 xkb/XKBAlloc.c                          |   14 +++---
 xkb/XKBGAlloc.c                         |    2 +-
 xkb/XKBMAlloc.c                         |   47 +++++++++----------
 xkb/maprules.c                          |   12 ++---
 xkb/xkb.c                               |   32 ++++++-------
 xkb/xkbActions.c                        |    4 +-
 xkb/xkbUtils.c                          |   76 ++++++++++++++++---------------
 xkb/xkmread.c                           |    2 +-
 151 files changed, 689 insertions(+), 627 deletions(-)
 create mode 100644 os/reallocarray.c

-- 
1.7.9.2



More information about the xorg-devel mailing list