Commit 56fa2348 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Font.c: replace memcpy by sprintf preventing possible buffer overflows

I am not sure about the maximum font name length in X but just in case use snprintf instead of memcpy to be sure nothing dangerous can happen here.
parent cac1af52
...@@ -733,7 +733,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -733,7 +733,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
{ {
XFontStruct *fontStruct; XFontStruct *fontStruct;
char *substFontBuf; char substFontBuf[512];;
/* X Logical Font Description Conventions /* X Logical Font Description Conventions
* require 14 fields in the font names. * require 14 fields in the font names.
...@@ -767,12 +767,9 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -767,12 +767,9 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
fprintf(stderr, "nxagentLoadBestQueryFont: Searching font '%s' .\n", fontName); fprintf(stderr, "nxagentLoadBestQueryFont: Searching font '%s' .\n", fontName);
#endif #endif
substFontBuf = (char *) malloc(sizeof(char) * 512);
numFontFields = nxagentSplitString(fontName, fontNameFields, FIELDS + 1, "-"); numFontFields = nxagentSplitString(fontName, fontNameFields, FIELDS + 1, "-");
memcpy(substFontBuf, "fixed\0", strlen("fixed") + 1); snprintf(substFontBuf, sizeof(substFontBuf), "%s", "fixed");
if (numFontFields <= FIELDS) if (numFontFields <= FIELDS)
{ {
...@@ -831,8 +828,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -831,8 +828,7 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
/* Found more accurate font */ /* Found more accurate font */
weight = tempWeight; weight = tempWeight;
memcpy(substFontBuf, nxagentRemoteFontList.list[i]->name, strlen(nxagentRemoteFontList.list[i]->name)); snprintf(substFontBuf, sizeof(substFontBuf), "%s", nxagentRemoteFontList.list[i]->name);
substFontBuf[strlen(nxagentRemoteFontList.list[i]->name)] = '\0';
#ifdef NXAGENT_RECONNECT_FONT_DEBUG #ifdef NXAGENT_RECONNECT_FONT_DEBUG
fprintf(stderr, "nxagentLoadBestQueryFont: Weight '%d' of more accurate font '%s' .\n", weight, substFontBuf); fprintf(stderr, "nxagentLoadBestQueryFont: Weight '%d' of more accurate font '%s' .\n", weight, substFontBuf);
...@@ -856,8 +852,6 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP ...@@ -856,8 +852,6 @@ static XFontStruct *nxagentLoadBestQueryFont(Display* dpy, char *fontName, FontP
fontStruct = nxagentLoadQueryFont(dpy, substFontBuf, pFont); fontStruct = nxagentLoadQueryFont(dpy, substFontBuf, pFont);
free (substFontBuf);
for (j = 0; j < numFontFields; j++) for (j = 0; j < numFontFields; j++)
{ {
free(fontNameFields[j]); free(fontNameFields[j]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment