libxdmcp: Changes to 'upstream-unstable'
.gitignore | 1
Array.c | 87 ++++++++++++++++++++++++++++---------------------
Fill.c | 22 ------------
Flush.c | 17 ---------
Key.c | 10 +++++
Makefile.am | 2 -
autogen.sh | 4 +-
configure.ac | 20 +++++++----
include/X11/Xdmcp.h | 2 -
test/Array.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
test/Makefile.am | 13 +++++++
11 files changed, 186 insertions(+), 84 deletions(-)
New commits:
commit 0c09444d276fbf46a0e8b427a4f6a325d0625742
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat Mar 21 09:39:14 2015 -0700
libXdmcp 1.1.2
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/configure.ac b/configure.ac
index d117aa1..608bab9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@
# Initialize Autoconf
AC_PREREQ([2.60])
-AC_INIT([libXdmcp], [1.1.1],
+AC_INIT([libXdmcp], [1.1.2],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXdmcp])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
commit 9f4cac7656b221ce2a8f97e7bd31e5e23126d001
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat Jan 17 10:37:09 2015 -0800
Add AC_USE_SYSTEM_EXTENSIONS to expose arc4random() interfaces in headers
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/configure.ac b/configure.ac
index cf6b309..d117aa1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,10 @@ AC_INIT([libXdmcp], [1.1.1],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], [libXdmcp])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
+# Set common system defines for POSIX extensions, such as _GNU_SOURCE
+# Must be called before any macros that run the compiler (like AC_PROG_LIBTOOL)
+# to avoid autoconf errors.
+AC_USE_SYSTEM_EXTENSIONS
# Initialize Automake
AM_INIT_AUTOMAKE([foreign dist-bzip2])
commit fe8eab93e9bcdbe8bb8052434bb5e676e3a0ee8f
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat May 31 21:39:32 2014 -0700
autogen.sh: Honor NOCONFIGURE=1
See http://people.gnome.org/~walters/docs/build-api.txt
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/autogen.sh b/autogen.sh
index 354f254..fc34bd5 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,4 +9,6 @@ cd $srcdir
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
-$srcdir/configure "$@"
+if test -z "$NOCONFIGURE"; then
+ $srcdir/configure "$@"
+fi
commit da9a25b208035448867f97cd92f3aed4b5bc53a9
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat May 31 21:38:41 2014 -0700
configure: Drop AM_MAINTAINER_MODE
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/autogen.sh b/autogen.sh
index 904cd67..354f254 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,4 +9,4 @@ cd $srcdir
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
-$srcdir/configure --enable-maintainer-mode "$@"
+$srcdir/configure "$@"
diff --git a/configure.ac b/configure.ac
index 4e85650..cf6b309 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,7 +29,6 @@ AC_CONFIG_HEADERS([config.h])
# Initialize Automake
AM_INIT_AUTOMAKE([foreign dist-bzip2])
-AM_MAINTAINER_MODE
# Initialize libtool
AC_LIBTOOL_WIN32_DLL
commit 089081dca4ba3598c6f9bf401c029378943b5854
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Sat May 25 10:18:33 2013 -0700
Also reject requests to allocate negative sized amounts of memory
Since the API is defined with size as a signed int, deal with it.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Array.c b/Array.c
index cb57d89..6b9b617 100644
--- a/Array.c
+++ b/Array.c
@@ -65,7 +65,7 @@ int
XdmcpAllocARRAY8 (ARRAY8Ptr array, int length)
{
/* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
- if (length > UINT16_MAX)
+ if ((length > UINT16_MAX) || (length < 0))
array->data = NULL;
else
array->data = xmalloc(length * sizeof (CARD8));
@@ -82,7 +82,7 @@ int
XdmcpAllocARRAY16 (ARRAY16Ptr array, int length)
{
/* length defined in ARRAY16 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
array->data = NULL;
else
array->data = xmalloc(length * sizeof (CARD16));
@@ -99,7 +99,7 @@ int
XdmcpAllocARRAY32 (ARRAY32Ptr array, int length)
{
/* length defined in ARRAY32 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
array->data = NULL;
else
array->data = xmalloc(length * sizeof (CARD32));
@@ -116,7 +116,7 @@ int
XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
{
/* length defined in ARRAYofARRAY8 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
array->data = NULL;
else
/*
@@ -159,7 +159,7 @@ XdmcpReallocARRAY8 (ARRAY8Ptr array, int length)
CARD8Ptr newData;
/* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
- if (length > UINT16_MAX)
+ if ((length > UINT16_MAX) || (length < 0))
return FALSE;
newData = (CARD8Ptr) xrealloc(array->data, length * sizeof (CARD8));
@@ -176,7 +176,7 @@ XdmcpReallocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
ARRAY8Ptr newData;
/* length defined in ARRAYofARRAY8 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
return FALSE;
newData = (ARRAY8Ptr) xrealloc(array->data, length * sizeof (ARRAY8));
@@ -196,7 +196,7 @@ XdmcpReallocARRAY16 (ARRAY16Ptr array, int length)
CARD16Ptr newData;
/* length defined in ARRAY16 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
return FALSE;
newData = (CARD16Ptr) xrealloc(array->data, length * sizeof (CARD16));
if (!newData)
@@ -212,7 +212,7 @@ XdmcpReallocARRAY32 (ARRAY32Ptr array, int length)
CARD32Ptr newData;
/* length defined in ARRAY32 struct is a CARD8 */
- if (length > UINT8_MAX)
+ if ((length > UINT8_MAX) || (length < 0))
return FALSE;
newData = (CARD32Ptr) xrealloc(array->data, length * sizeof (CARD32));
diff --git a/test/Array.c b/test/Array.c
index b246ba8..786fade 100644
--- a/test/Array.c
+++ b/test/Array.c
@@ -52,6 +52,10 @@ TestAllocOversizeArrays(void)
TestAllocOversize(ARRAY16, UINT8_MAX + 1);
TestAllocOversize(ARRAY32, UINT8_MAX + 1);
TestAllocOversize(ARRAYofARRAY8, UINT8_MAX + 1);
+ TestAllocOversize(ARRAY8, -1);
+ TestAllocOversize(ARRAY16, -1);
+ TestAllocOversize(ARRAY32, -1);
+ TestAllocOversize(ARRAYofARRAY8, -1);
}
static void
commit 2da1bcb656febdab9345f1fec31c974fd7b409bc
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Fri May 24 23:19:23 2013 -0700
Ensure ARRAYofARRAY8 pointers are initialized to NULL
Use calloc for the array of pointers to ensure pointers are cleared out
so we don't try to free garbage if XdmcpDisposeARRAYofARRAY8 is called
before the caller sets them to valid pointers.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Array.c b/Array.c
index c1456e1..cb57d89 100644
--- a/Array.c
+++ b/Array.c
@@ -44,6 +44,15 @@ xmalloc(size_t size)
}
/*
+ * This variant of calloc does not return NULL if zero count is passed into.
+ */
+static void *
+xcalloc(size_t n, size_t size)
+{
+ return calloc(n ? n : 1, size);
+}
+
+/*
* This variant of realloc does not return NULL if zero size is passed into
*/
static void *
@@ -110,7 +119,12 @@ XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
if (length > UINT8_MAX)
array->data = NULL;
else
- array->data = xmalloc(length * sizeof (ARRAY8));
+ /*
+ * Use calloc to ensure the pointers are cleared out so we
+ * don't try to free garbage if XdmcpDisposeARRAYofARRAY8()
+ * is called before the caller sets them to valid pointers.
+ */
+ array->data = xcalloc(length, sizeof (ARRAY8));
if (array->data == NULL) {
array->length = 0;
@@ -168,6 +182,9 @@ XdmcpReallocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
newData = (ARRAY8Ptr) xrealloc(array->data, length * sizeof (ARRAY8));
if (!newData)
return FALSE;
+ if (length > array->length)
+ memset(newData + array->length, 0,
+ (length - array->length) * sizeof (ARRAY8));
array->length = (CARD8) length;
array->data = newData;
return TRUE;
diff --git a/test/Array.c b/test/Array.c
index 0f3430e..b246ba8 100644
--- a/test/Array.c
+++ b/test/Array.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
#include <X11/Xdmcp.h>
#include <inttypes.h>
@@ -53,10 +54,35 @@ TestAllocOversizeArrays(void)
TestAllocOversize(ARRAYofARRAY8, UINT8_MAX + 1);
}
+static void
+TestZeroFillARRAYofARRAY8(void)
+{
+ ARRAYofARRAY8 aa;
+ int result;
+ char *noise;
+
+ printf("Checking XdmcpAllocARRAYofARRAY8 zero fills array...\n");
+ /* prefill memory with junk - hopefully next malloc will pick up some */
+ noise = malloc(32 * sizeof(ARRAY8));
+ memset(noise, 0xdeadbeef, 32 * sizeof(ARRAY8));
+ free(noise);
+ result = XdmcpAllocARRAYofARRAY8(&aa, 32);
+ assert(result == TRUE);
+ assert(aa.length == 32);
+ assert(aa.data[4].data == NULL);
+ printf("Checking XdmcpReallocARRAYofARRAY8 zero fills array...\n");
+ result = XdmcpAllocARRAYofARRAY8(&aa, 48);
+ assert(result == TRUE);
+ assert(aa.length == 48);
+ assert(aa.data[40].data == NULL);
+ XdmcpDisposeARRAYofARRAY8(&aa);
+}
+
int
main(int argc, char **argv)
{
TestAllocOversizeArrays();
+ TestZeroFillARRAYofARRAY8();
exit(0);
}
commit 787c4c79be18373f58aeaf2fe543f30fe3af2bd1
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Fri May 24 22:58:41 2013 -0700
Ensure ARRAY* structs are zero'ed out when oversize values are passed
Previous fix missed a case in which we returned failure, but didn't
fill in the data pointer & size values.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Array.c b/Array.c
index f529781..c1456e1 100644
--- a/Array.c
+++ b/Array.c
@@ -55,80 +55,68 @@ xrealloc(void *ptr, size_t size)
int
XdmcpAllocARRAY8 (ARRAY8Ptr array, int length)
{
- CARD8Ptr newData;
-
/* length defined in ARRAY8 struct is a CARD16 (not CARD8 like the rest) */
if (length > UINT16_MAX)
- return FALSE;
+ array->data = NULL;
+ else
+ array->data = xmalloc(length * sizeof (CARD8));
- newData = (CARD8Ptr) xmalloc(length * sizeof (CARD8));
- if (!newData) {
+ if (array->data == NULL) {
array->length = 0;
- array->data = NULL;
return FALSE;
}
array->length = (CARD16) length;
- array->data = newData;
return TRUE;
}
int
XdmcpAllocARRAY16 (ARRAY16Ptr array, int length)
{
- CARD16Ptr newData;
-
/* length defined in ARRAY16 struct is a CARD8 */
if (length > UINT8_MAX)
- return FALSE;
+ array->data = NULL;
+ else
+ array->data = xmalloc(length * sizeof (CARD16));
- newData = (CARD16Ptr) xmalloc(length * sizeof (CARD16));
- if (!newData) {
+ if (array->data == NULL) {
array->length = 0;
- array->data = NULL;
return FALSE;
}
array->length = (CARD8) length;
- array->data = newData;
return TRUE;
}
int
XdmcpAllocARRAY32 (ARRAY32Ptr array, int length)
{
- CARD32Ptr newData;
-
/* length defined in ARRAY32 struct is a CARD8 */
if (length > UINT8_MAX)
- return FALSE;
+ array->data = NULL;
+ else
+ array->data = xmalloc(length * sizeof (CARD32));
- newData = (CARD32Ptr) xmalloc(length * sizeof (CARD32));
- if (!newData) {
+ if (array->data == NULL) {
array->length = 0;
- array->data = NULL;
return FALSE;
}
array->length = (CARD8) length;
- array->data = newData;
return TRUE;
}
int
XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
{
- ARRAY8Ptr newData;
-
/* length defined in ARRAYofARRAY8 struct is a CARD8 */
if (length > UINT8_MAX)
- return FALSE;
+ array->data = NULL;
+ else
+ array->data = xmalloc(length * sizeof (ARRAY8));
- newData = (ARRAY8Ptr) xmalloc(length * sizeof (ARRAY8));
- if (!newData) {
+ if (array->data == NULL) {
array->length = 0;
- array->data = NULL;
return FALSE;
}
array->length = (CARD8) length;
- array->data = newData;
return TRUE;
}
commit 9089ae455f9df222aa85bbbcb4526874c0d97099
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Fri May 24 22:24:55 2013 -0700
Add unit tests for Array allocation functions
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/.gitignore b/.gitignore
index 07ac69e..edf9a16 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,3 +76,4 @@ core
# Edit the following section as needed
# For example, !report.pc overrides *.pc. See 'man gitignore'
#
+test/Array
diff --git a/Makefile.am b/Makefile.am
index c3b85aa..ca54099 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS=doc
+SUBDIRS=doc . test
lib_LTLIBRARIES = libXdmcp.la
diff --git a/configure.ac b/configure.ac
index d8ddfae..4e85650 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,10 +35,10 @@ AM_MAINTAINER_MODE
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
-# Require xorg-macros minimum of 1.12 for DocBook external references
+# Require xorg-macros minimum of 1.16 for unit testing with memory checks
m4_ifndef([XORG_MACROS_VERSION],
- [m4_fatal([must install xorg-macros 1.12 or later before running autoconf/autogen])])
-XORG_MACROS_VERSION(1.12)
+ [m4_fatal([must install xorg-macros 1.16 or later before running autoconf/autogen])])
+XORG_MACROS_VERSION(1.16)
XORG_DEFAULT_OPTIONS
XORG_ENABLE_DOCS
XORG_WITH_XMLTO(0.0.22)
@@ -72,7 +72,11 @@ AM_CONDITIONAL(HASXDMAUTH,test x$HASXDMAUTH = xyes)
XORG_WITH_LINT
XORG_LINT_LIBRARY([Xdmcp])
+# --enable-unit-tests
+XORG_ENABLE_UNIT_TESTS([yes])
+
AC_CONFIG_FILES([Makefile
doc/Makefile
+ test/Makefile
xdmcp.pc])
AC_OUTPUT
diff --git a/test/Array.c b/test/Array.c
new file mode 100644
index 0000000..0f3430e
--- /dev/null
+++ b/test/Array.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <X11/Xdmcp.h>
+#include <inttypes.h>
+
+/* Test what happens if you try to allocate an array with too many entries */
+#define TestAllocOversize(type, len) { \
+ type newArray = { -1, (void *) -1 }; \
+ int result; \
+ printf("Checking XdmcpAlloc%s(%d)...\n", #type, len); \
+ result = XdmcpAlloc##type(&newArray, len) ; \
+ assert(result == FALSE); \
+ assert(newArray.length == 0); \
+ assert(newArray.data == NULL); \
+ printf("Checking XdmcpRealloc%s(%d)...\n", #type, len); \
+ result = XdmcpRealloc##type(&newArray, len); \
+ assert(result == FALSE); \
+ assert(newArray.length == 0); \
+ assert(newArray.data == NULL); \
+ XdmcpDispose##type(&newArray); \
+}
+
+static void
+TestAllocOversizeArrays(void)
+{
+ TestAllocOversize(ARRAY8, UINT16_MAX + 1);
+ TestAllocOversize(ARRAY16, UINT8_MAX + 1);
+ TestAllocOversize(ARRAY32, UINT8_MAX + 1);
+ TestAllocOversize(ARRAYofARRAY8, UINT8_MAX + 1);
+}
+
+int
+main(int argc, char **argv)
+{
+ TestAllocOversizeArrays();
+
+ exit(0);
+}
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..d86719e
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,13 @@
+if ENABLE_UNIT_TESTS
+
+check_PROGRAMS = Array
+
+TESTS=$(check_PROGRAMS)
+
+AM_CFLAGS = $(CWARNFLAGS) $(XDMCP_CFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/include
+LDADD= $(top_builddir)/libXdmcp.la $(XDMCP_LIBS)
+
+AM_TESTS_ENVIRONMENT = $(XORG_MALLOC_DEBUG_ENV)
+
+endif ENABLE_UNIT_TESTS
commit 66514a4af7eaa47e8718434356d7efce95e570cf
Author: Matthieu Herrb <matthieu.herrb@laas.fr>
Date: Sun Aug 4 10:42:57 2013 +0200
Use arc4random when available to produce the XDM-AUTHENTICATION1 key
arc4random() and associated functions can be found in libbsd on
GNU/Linux systems.
Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Key.c b/Key.c
index aa4add6..a09b316 100644
--- a/Key.c
+++ b/Key.c
@@ -32,6 +32,11 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xmd.h>
#include <X11/Xdmcp.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/stdlib.h> /* for arc4random_buf() */
+#endif
+
+#ifndef HAVE_ARC4RANDOM_BUF
static void
getbits (long data, unsigned char *dst)
{
@@ -40,6 +45,7 @@ getbits (long data, unsigned char *dst)
dst[2] = (data >> 16) & 0xff;
dst[3] = (data >> 24) & 0xff;
}
+#endif
#define Time_t time_t
@@ -59,6 +65,7 @@ getbits (long data, unsigned char *dst)
void
XdmcpGenerateKey (XdmAuthKeyPtr key)
{
+#ifndef HAVE_ARC4RANDOM_BUF
long lowbits, highbits;
srandom ((int)getpid() ^ time((Time_t *)0));
@@ -66,6 +73,9 @@ XdmcpGenerateKey (XdmAuthKeyPtr key)
highbits = random ();
getbits (lowbits, key->data);
getbits (highbits, key->data + 4);
+#else
+ arc4random_buf(key->data, 8);
+#endif
}
int
diff --git a/configure.ac b/configure.ac
index 08c046a..d8ddfae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,7 +53,8 @@ AC_PROG_LN_S
AC_SEARCH_LIBS([recvfrom],[socket])
# Checks for library functions.
-AC_CHECK_FUNCS([srand48 lrand48])
+AC_CHECK_LIB([bsd], [arc4random_buf])
+AC_CHECK_FUNCS([srand48 lrand48 arc4random_buf])
# Obtain compiler/linker options for depedencies
PKG_CHECK_MODULES(XDMCP, xproto)
commit 0b443c1b769b9c9a3b45b4252afe07e18b709ff4
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Fri Apr 19 15:16:51 2013 -0700
Make XdmcpCopyARRAY8 call XdmcpAllocARRAY8 instead of replicating it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Array.c b/Array.c
index 4f0561f..f529781 100644
--- a/Array.c
+++ b/Array.c
@@ -145,12 +145,8 @@ XdmcpARRAY8Equal (const ARRAY8Ptr array1, const ARRAY8Ptr array2)
int
XdmcpCopyARRAY8 (const ARRAY8Ptr src, ARRAY8Ptr dst)
{
- dst->data = (CARD8 *) xmalloc(src->length * sizeof (CARD8));
- if (!dst->data) {
- dst->length = 0;
+ if (!XdmcpAllocARRAY8(dst, src->length))
return FALSE;
- }
- dst->length = src->length;
memmove (dst->data, src->data, src->length * sizeof (CARD8));
return TRUE;
}
commit 1222f974442f3d419664be4faca576f5f1457666
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Tue Apr 2 00:07:54 2013 -0700
Ensure ARRAY* structs are zero'ed out when allocation fails
In the past some callers forgot to either initialize themselves or to
check the return values, so could try to read or write to uninitialized
pointers - we set the pointer to NULL & the size to 0 to avoid that.
Reported-by: Ilja Van Sprundel <ivansprundel@ioactive.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Array.c b/Array.c
index 8862773..4f0561f 100644
--- a/Array.c
+++ b/Array.c
@@ -62,8 +62,11 @@ XdmcpAllocARRAY8 (ARRAY8Ptr array, int length)
return FALSE;
newData = (CARD8Ptr) xmalloc(length * sizeof (CARD8));
- if (!newData)
+ if (!newData) {
+ array->length = 0;
+ array->data = NULL;
return FALSE;
+ }
array->length = (CARD16) length;
array->data = newData;
return TRUE;
@@ -79,8 +82,11 @@ XdmcpAllocARRAY16 (ARRAY16Ptr array, int length)
return FALSE;
newData = (CARD16Ptr) xmalloc(length * sizeof (CARD16));
- if (!newData)
+ if (!newData) {
+ array->length = 0;
+ array->data = NULL;
return FALSE;
+ }
array->length = (CARD8) length;
array->data = newData;
return TRUE;
@@ -96,8 +102,11 @@ XdmcpAllocARRAY32 (ARRAY32Ptr array, int length)
return FALSE;
newData = (CARD32Ptr) xmalloc(length * sizeof (CARD32));
- if (!newData)
+ if (!newData) {
+ array->length = 0;
+ array->data = NULL;
return FALSE;
+ }
array->length = (CARD8) length;
array->data = newData;
return TRUE;
@@ -113,8 +122,11 @@ XdmcpAllocARRAYofARRAY8 (ARRAYofARRAY8Ptr array, int length)
return FALSE;
newData = (ARRAY8Ptr) xmalloc(length * sizeof (ARRAY8));
- if (!newData)
+ if (!newData) {
+ array->length = 0;
+ array->data = NULL;
return FALSE;
+ }
array->length = (CARD8) length;
array->data = newData;
return TRUE;
@@ -133,10 +145,12 @@ XdmcpARRAY8Equal (const ARRAY8Ptr array1, const ARRAY8Ptr array2)
int
XdmcpCopyARRAY8 (const ARRAY8Ptr src, ARRAY8Ptr dst)
{
- dst->length = src->length;
- dst->data = (CARD8 *) xmalloc(dst->length * sizeof (CARD8));
- if (!dst->data)
+ dst->data = (CARD8 *) xmalloc(src->length * sizeof (CARD8));
+ if (!dst->data) {
+ dst->length = 0;
return FALSE;
+ }
+ dst->length = src->length;
memmove (dst->data, src->data, src->length * sizeof (CARD8));
return TRUE;
}
commit ca65a92405500393f09d34388edbbf6350e6c146
Author: Alan Coopersmith <alan.coopersmith@oracle.com>
Date: Wed Dec 26 23:39:58 2012 -0800
Remove unused TLI ("STREAMSCONN") code from libXdmcp
Has never been converted to build in modular builds, so has been unusable
since X11R7.0 release in 2005. All known platforms with TLI/XTI support
that X11R7 & later releases run on also have (and mostly prefer) BSD
socket support for their networking API.
Mostly performed via "unifdef -USTREAMSCONN", followed by manual cleanup.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
diff --git a/Fill.c b/Fill.c
index 98c324f..61cd974 100644
--- a/Fill.c
+++ b/Fill.c
@@ -36,24 +36,16 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xdmcp.h>
#include <stdlib.h>
-#ifdef STREAMSCONN
-#include <tiuser.h>
-#else
#ifdef WIN32
#include <X11/Xwinsock.h>
#else
#include <sys/socket.h>
#endif
-#endif
int
XdmcpFill (int fd, XdmcpBufferPtr buffer, XdmcpNetaddr from, int *fromlen)
{
BYTE *newBuf;
-#ifdef STREAMSCONN
- struct t_unitdata dataunit;
- int gotallflag, result;
-#endif
if (buffer->size < XDM_MAX_MSGLEN)
{
@@ -66,22 +58,8 @@ XdmcpFill (int fd, XdmcpBufferPtr buffer, XdmcpNetaddr from, int *fromlen)
}
}
buffer->pointer = 0;
-#ifdef STREAMSCONN
- dataunit.addr.buf = from;
- dataunit.addr.maxlen = *fromlen;
- dataunit.opt.maxlen = 0; /* don't care to know about options */
- dataunit.udata.buf = (char *)buffer->data;
- dataunit.udata.maxlen = buffer->size;
- result = t_rcvudata (fd, &dataunit, &gotallflag);
- if (result < 0) {
- return FALSE;
- }
- buffer->count = dataunit.udata.len;
- *fromlen = dataunit.addr.len;
-#else
buffer->count = recvfrom (fd, (char*)buffer->data, buffer->size, 0,
(struct sockaddr *)from, (void *)fromlen);
-#endif
if (buffer->count < 6) {
buffer->count = 0;
return FALSE;
diff --git a/Flush.c b/Flush.c
index cdcd1f0..1654846 100644
--- a/Flush.c
+++ b/Flush.c
@@ -35,36 +35,19 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xmd.h>
#include <X11/Xdmcp.h>
-#ifdef STREAMSCONN
-#include <tiuser.h>
-#else
#ifdef WIN32
#include <X11/Xwinsock.h>
#else
#include <sys/socket.h>
#endif
-#endif
int
XdmcpFlush (int fd, XdmcpBufferPtr buffer, XdmcpNetaddr to, int tolen)
{
int result;
-#ifdef STREAMSCONN
- struct t_unitdata dataunit;
-
- dataunit.addr.buf = to;
- dataunit.addr.len = tolen;
- dataunit.opt.len = 0; /* default options */
- dataunit.udata.buf = (char *)buffer->data;
- dataunit.udata.len = buffer->pointer;
- result = t_sndudata(fd, &dataunit);
- if (result < 0)
- return FALSE;
-#else
result = sendto (fd, (char *)buffer->data, buffer->pointer, 0,
(struct sockaddr *)to, tolen);
if (result != buffer->pointer)
return FALSE;
-#endif
return TRUE;
}
diff --git a/include/X11/Xdmcp.h b/include/X11/Xdmcp.h
index 99a5f95..0b531de 100644
--- a/include/X11/Xdmcp.h
+++ b/include/X11/Xdmcp.h
@@ -114,7 +114,7 @@ typedef struct _XdmAuthKey {
/* implementation-independent network address structure.
- Equiv to sockaddr* for sockets and netbuf* for STREAMS. */
+ Equiv to sockaddr* for sockets. */
typedef char *XdmcpNetaddr;
Reply to: