diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0e325e2..1d4e1bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,14 @@ add_definitions(-D__BUILD__="${BUILD}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -UNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -UNDEBUG")
+# We want to keep our asserts even in release builds so remove NDEBUG
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG")
+set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -UNDEBUG")
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG")
+set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG")
+set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG")
+
if(NOT DEFINED BUILD_WINVNC)
set(BUILD_WINVNC 1)
endif()
diff --git a/common/Xregion/Region.c b/common/Xregion/Region.c
index 604ecde..4bb52ea 100644
--- a/common/Xregion/Region.c
+++ b/common/Xregion/Region.c
@@ -1083,6 +1083,8 @@ miRegionOp(newReg, reg1, reg2, overlapFunc, nonOverlap1Func, nonOverlap2Func)
newReg->size = 1;
Xfree((char *) newReg->rects);
newReg->rects = (BoxPtr) Xmalloc(sizeof(BoxRec));
+ if (! newReg->rects)
+ newReg->size = 0;
}
}
Xfree ((char *) oldRects);
diff --git a/unix/vncconfig/vncExt.c b/unix/vncconfig/vncExt.c
index ff5532b..c2e6d3c 100644
--- a/unix/vncconfig/vncExt.c
+++ b/unix/vncconfig/vncExt.c
@@ -109,6 +109,10 @@ Bool XVncExtGetParam(Display* dpy, const char* param, char** value, int* len)
if (rep.success) {
*len = rep.valueLen;
*value = (char*) Xmalloc (*len+1);
+ if (!*value) {
+ _XEatData(dpy, (*len+1)&~1);
+ return False;
+ }
_XReadPad(dpy, *value, *len);
(*value)[*len] = 0;
}
@@ -141,6 +145,10 @@ char* XVncExtGetParamDesc(Display* dpy, const char* param)
}
if (rep.success) {
desc = (char*)Xmalloc(rep.descLen+1);
+ if (!*desc) {
+ _XEatData(dpy, (rep.descLen+1)&~1);
+ return False;
+ }
_XReadPad(dpy, desc, rep.descLen);
desc[rep.descLen] = 0;
}
@@ -243,6 +251,10 @@ Bool XVncExtGetClientCutText(Display* dpy, char** str, int* len)
SyncHandle();
*len = rep.textLen;
*str = (char*) Xmalloc (*len+1);
+ if (!*str) {
+ _XEatData(dpy, (*len+1)&~1);
+ return False;
+ }
_XReadPad(dpy, *str, *len);
(*str)[*len] = 0;
return True;
@@ -312,9 +324,15 @@ Bool XVncExtGetQueryConnect(Display* dpy, char** addr, char** user,
SyncHandle();
*addr = Xmalloc(rep.addrLen+1);
+ *user = Xmalloc(rep.userLen+1);
+ if (!*addr || !*user) {
+ Xfree(*addr);
+ Xfree(*user);
+ _XEatData(dpy, (rep.addrLen+1)&~1 + (rep.userLen+1)&~1);
+ return False;
+ }
_XReadPad(dpy, *addr, rep.addrLen);
(*addr)[rep.addrLen] = 0;
- *user = Xmalloc(rep.userLen+1);
_XReadPad(dpy, *user, rep.userLen);
(*user)[rep.userLen] = 0;
*timeout = rep.timeout;
diff --git a/unix/vncconfig/vncconfig.cxx b/unix/vncconfig/vncconfig.cxx
index f70cc71..bffdfbe 100644
--- a/unix/vncconfig/vncconfig.cxx
+++ b/unix/vncconfig/vncconfig.cxx
@@ -215,6 +215,10 @@ public:
if (cutText)
XFree(cutText);
cutText = (char*)malloc(nitems); // assuming XFree() same as free()
+ if (!cutText) {
+ vlog.error("unable to allocate selection buffer");
+ return;
+ }
memcpy(cutText, data, nitems);
cutTextLen = nitems;
vlog.debug("sending %s selection as server cut text: '%.*s%s'",