# HG changeset patch # User Rik # Date 1274059739 25200 # Node ID 60542efcfa2cec85817873995bf6e270fe874ebc # Parent d022061c288d3804b8f1d94e7fa2c861fa988f52 Check input arguments for size and type (bug #29861). Prevents segmentation fault with odd inputs. diff -r d022061c288d -r 60542efcfa2c scripts/ChangeLog --- a/scripts/ChangeLog Fri May 14 06:59:41 2010 +0200 +++ b/scripts/ChangeLog Sun May 16 18:28:59 2010 -0700 @@ -1,3 +1,9 @@ +2010-05-16 Rik + + * scripts/plot/contourc.m, scripts/plot/private/__contour__.m, + scripts/plot/surface.m, scripts/plot/surfnorm.m: Check input + arguments for size and type (bug #29861). + 2010-05-13 John W. Eaton * help/help.m: Avoid unnecessary use of varargout. diff -r d022061c288d -r 60542efcfa2c scripts/plot/contourc.m --- a/scripts/plot/contourc.m Fri May 14 06:59:41 2010 +0200 +++ b/scripts/plot/contourc.m Sun May 16 18:28:59 2010 -0700 @@ -64,9 +64,6 @@ if (nargin == 1) vn = 10; z = varargin{1}; - [nr, nc] = size (z); - x = 1:nc; - y = 1:nr; elseif (nargin == 2) vn = varargin{2}; z = varargin{1}; @@ -87,6 +84,10 @@ print_usage (); endif + if (!ismatrix (z) || isvector (z) || isscalar (z)) + error ("contourc: z argument must be a matrix"); + endif + if (isscalar (vn)) vv = linspace (min (z(:)), max (z(:)), vn+2)(2:end-1); else diff -r d022061c288d -r 60542efcfa2c scripts/plot/private/__contour__.m --- a/scripts/plot/private/__contour__.m Fri May 14 06:59:41 2010 +0200 +++ b/scripts/plot/private/__contour__.m Sun May 16 18:28:59 2010 -0700 @@ -88,6 +88,9 @@ y1 = varargin{4}; z1 = varargin{5}; endif + if (!ismatrix (z1) || isvector (z1) || isscalar (z1)) + error ("__contour__: z argument must be a matrix"); + endif if (length (varargin) == 4 || length (varargin) == 6) vn = varargin {end}; vnauto = false; diff -r d022061c288d -r 60542efcfa2c scripts/plot/surface.m --- a/scripts/plot/surface.m Fri May 14 06:59:41 2010 +0200 +++ b/scripts/plot/surface.m Sun May 16 18:28:59 2010 -0700 @@ -18,7 +18,7 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) +## @deftypefn {Function File} {} surface (@var{x}, @var{y}, @var{z}, @var{c}) ## @deftypefnx {Function File} {} surface (@var{x}, @var{y}, @var{z}) ## @deftypefnx {Function File} {} surface (@var{z}, @var{c}) ## @deftypefnx {Function File} {} surface (@var{z}) @@ -82,7 +82,7 @@ c = varargin{4}; if (! size_equal (z, c)) - error ("surface: z and c must have same size"); + error ("surface: z and c must have the same size"); endif if (isvector (x) && isvector (y) && ismatrix (z)) if (rows (z) == length (y) && columns (z) == length (x)) @@ -93,7 +93,7 @@ endif elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) if (! size_equal (x, y, z)) - error ("surface: x, y, and z must have same dimensions"); + error ("surface: x, y, and z must have the same dimensions"); endif else error ("surface: x and y must be vectors and z must be a matrix"); @@ -112,7 +112,7 @@ endif elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) if (! size_equal (x, y, z)) - error ("surface: x, y, and z must have same dimensions"); + error ("surface: x, y, and z must have the same dimensions"); endif else error ("surface: x and y must be vectors and z must be a matrix"); @@ -120,22 +120,22 @@ elseif (firststring == 3) z = varargin{1}; c = varargin{2}; - if (ismatrix (z)) + if (ismatrix (z) && !isvector (z) && !isscalar (z)) [nr, nc] = size (z); x = 1:nc; y = (1:nr)'; else - error ("surface: argument must be a matrix"); + error ("surface: z argument must be a matrix"); endif elseif (firststring == 2) z = varargin{1}; c = z; - if (ismatrix (z)) + if (ismatrix (z) && !isvector (z) && !isscalar (z)) [nr, nc] = size (z); x = 1:nc; y = (1:nr)'; else - error ("surface: argument must be a matrix"); + error ("surface: z argument must be a matrix"); endif else bad_usage = true; diff -r d022061c288d -r 60542efcfa2c scripts/plot/surfnorm.m --- a/scripts/plot/surfnorm.m Fri May 14 06:59:41 2010 +0200 +++ b/scripts/plot/surfnorm.m Sun May 16 18:28:59 2010 -0700 @@ -71,8 +71,12 @@ ioff = 4; endif - if (nargout == 0) + if (!ismatrix (z) || isvector (z) || isscalar (z)) + error ("surfnorm: z argument must be a matrix"); endif + if (! size_equal (x, y, z)) + error ("surfnorm: x, y, and z must have the same dimensions"); + endif ## Make life easier, and avoid having to do the extrapolation later, do ## a simpler linear extrapolation here. This is approximative, and works