diff options
author | Pierre Ossman <ossman@cendio.se> | 2015-02-26 14:18:49 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2015-02-26 14:18:49 +0100 |
commit | c67778faf65c3ddbb8692188fdeac30f7ec79963 (patch) | |
tree | 46a43808cddd71fafc301bed1865a89f7eb16bfb | |
parent | 84266a5d6570be91bb7949fc377bef9fe2f42d87 (diff) | |
parent | e652878d4abacaf4982078b3503384cbd525d35e (diff) | |
download | tigervnc-c67778faf65c3ddbb8692188fdeac30f7ec79963.tar.gz tigervnc-c67778faf65c3ddbb8692188fdeac30f7ec79963.zip |
Merge branch 'cmdline-crash' of https://github.com/twaugh/tigervnc
-rw-r--r-- | unix/xserver/hw/vnc/xvnc.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/unix/xserver/hw/vnc/xvnc.c b/unix/xserver/hw/vnc/xvnc.c index 80198958..cc87efb0 100644 --- a/unix/xserver/hw/vnc/xvnc.c +++ b/unix/xserver/hw/vnc/xvnc.c @@ -341,6 +341,13 @@ Bool displayNumFree(int num) return TRUE; } +#define fail_unless_args(_argc,_i,_n) \ + if (_i + _n >= _argc) \ + { \ + UseMsg(); \ + return 0; \ + } + int ddxProcessArgument(int argc, char *argv[], int i) { @@ -360,12 +367,13 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */ { int screenNum; - if (i + 2 >= argc) UseMsg(); + fail_unless_args(argc, i, 2); screenNum = atoi(argv[i+1]); if (screenNum < 0 || screenNum >= MAXSCREENS) { ErrorF("Invalid screen number %d\n", screenNum); UseMsg(); + return 0; } if (3 != sscanf(argv[i+2], "%dx%dx%d", &vfbScreens[screenNum].fb.width, @@ -374,6 +382,7 @@ ddxProcessArgument(int argc, char *argv[], int i) { ErrorF("Invalid screen configuration %s\n", argv[i+2]); UseMsg(); + return 0; } if (screenNum >= vfbNumScreens) @@ -386,13 +395,15 @@ ddxProcessArgument(int argc, char *argv[], int i) { int depth, ret = 1; - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; while ((i < argc) && (depth = atoi(argv[i++])) != 0) { if (depth < 0 || depth > 32) { ErrorF("Invalid pixmap depth %d\n", depth); UseMsg(); + return 0; } vfbPixmapDepths[depth] = TRUE; ret++; @@ -415,7 +426,8 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */ { Pixel pix; - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; pix = atoi(argv[i]); if (-1 == lastScreen) { @@ -435,7 +447,8 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */ { Pixel pix; - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; pix = atoi(argv[i]); if (-1 == lastScreen) { @@ -455,7 +468,8 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */ { unsigned int linebias; - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; linebias = atoi(argv[i]); if (-1 == lastScreen) { @@ -482,18 +496,21 @@ ddxProcessArgument(int argc, char *argv[], int i) if (strcmp(argv[i], "-geometry") == 0) { - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; if (sscanf(argv[i],"%dx%d",&vfbScreens[0].fb.width, &vfbScreens[0].fb.height) != 2) { ErrorF("Invalid geometry %s\n", argv[i]); UseMsg(); + return 0; } return 2; } if (strcmp(argv[i], "-depth") == 0) { - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; vfbScreens[0].fb.depth = atoi(argv[i]); return 2; } @@ -502,10 +519,12 @@ ddxProcessArgument(int argc, char *argv[], int i) { char rgbbgr[4]; int bits1, bits2, bits3; - if (++i >= argc) UseMsg(); + fail_unless_args(argc, i, 1); + ++i; if (sscanf(argv[i], "%3s%1d%1d%1d", rgbbgr,&bits1,&bits2,&bits3) < 4) { ErrorF("Invalid pixel format %s\n", argv[i]); UseMsg(); + return 0; } #define SET_PIXEL_FORMAT(vfbScreen) \ @@ -523,6 +542,7 @@ ddxProcessArgument(int argc, char *argv[], int i) } else { \ ErrorF("Invalid pixel format %s\n", argv[i]); \ UseMsg(); \ + return 0; \ } if (-1 == lastScreen) |