aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/X11/FontNames.c
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-10-13 14:02:51 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-10-13 14:02:51 +0200
commit133c91f732c6259fa9099100cd5b781d5b1cbfa1 (patch)
tree478aa88a8c42cbcb8221dd6680a16131556b49be /nx-X11/lib/X11/FontNames.c
parent051d521f6e20761ba6831cecd91883da960fa931 (diff)
parenta9f623f0a63372ca0705e8394fadf514dec55b1c (diff)
downloadnx-libs-133c91f732c6259fa9099100cd5b781d5b1cbfa1.tar.gz
nx-libs-133c91f732c6259fa9099100cd5b781d5b1cbfa1.tar.bz2
nx-libs-133c91f732c6259fa9099100cd5b781d5b1cbfa1.zip
Merge branch 'uli42-pr/libX11_debian_backports' into 3.6.x
Attributes GH PR #215: https://github.com/ArcticaProject/nx-libs/pull/215
Diffstat (limited to 'nx-X11/lib/X11/FontNames.c')
-rw-r--r--nx-X11/lib/X11/FontNames.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/nx-X11/lib/X11/FontNames.c b/nx-X11/lib/X11/FontNames.c
index 3018cf2cf..b5bc7b4ba 100644
--- a/nx-X11/lib/X11/FontNames.c
+++ b/nx-X11/lib/X11/FontNames.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include <limits.h>
char **
XListFonts(
@@ -40,11 +41,13 @@ int *actualCount) /* RETURN */
register long nbytes;
register unsigned i;
register int length;
- char **flist;
- char *ch;
+ char **flist = NULL;
+ char *ch = NULL;
+ char *chend;
+ int count = 0;
xListFontsReply rep;
register xListFontsReq *req;
- register long rlen;
+ unsigned long rlen;
LockDisplay(dpy);
GetReq(ListFonts, req);
@@ -62,15 +65,17 @@ int *actualCount) /* RETURN */
}
if (rep.nFonts) {
- flist = (char **)Xmalloc ((unsigned)rep.nFonts * sizeof(char *));
- rlen = rep.length << 2;
- ch = (char *) Xmalloc((unsigned) (rlen + 1));
+ flist = Xmalloc (rep.nFonts * sizeof(char *));
+ if (rep.length < (LONG_MAX >> 2)) {
+ rlen = rep.length << 2;
+ ch = Xmalloc(rlen + 1);
/* +1 to leave room for last null-terminator */
+ }
if ((! flist) || (! ch)) {
if (flist) Xfree((char *) flist);
if (ch) Xfree(ch);
- _XEatData(dpy, (unsigned long) rlen);
+ _XEatDataWords(dpy, rep.length);
*actualCount = 0;
UnlockDisplay(dpy);
SyncHandle();
@@ -81,17 +86,21 @@ int *actualCount) /* RETURN */
/*
* unpack into null terminated strings.
*/
+ chend = ch + (rlen + 1);
length = *(unsigned char *)ch;
*ch = 1; /* make sure it is non-zero for XFreeFontNames */
for (i = 0; i < rep.nFonts; i++) {
- flist[i] = ch + 1; /* skip over length */
- ch += length + 1; /* find next length ... */
- length = *(unsigned char *)ch;
- *ch = '\0'; /* and replace with null-termination */
+ if (ch + length < chend) {
+ flist[i] = ch + 1; /* skip over length */
+ ch += length + 1; /* find next length ... */
+ length = *(unsigned char *)ch;
+ *ch = '\0'; /* and replace with null-termination */
+ count++;
+ } else
+ flist[i] = NULL;
}
}
- else flist = (char **) NULL;
- *actualCount = rep.nFonts;
+ *actualCount = count;
UnlockDisplay(dpy);
SyncHandle();
return (flist);