summaryrefslogtreecommitdiff
path: root/xkb
diff options
context:
space:
mode:
authorAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2005-02-01 18:14:01 +0000
committerAlexander Gottwald <alexander.gottwald@s1999.tu-chemnitz.de>2005-02-01 18:14:01 +0000
commit2f0bdf77dd37d1763c4f4f409d55a6aad6031b9f (patch)
tree712e6534ccdfe5652aa74478cbab73ce58ef69d6 /xkb
parentd3ca132061a861cb9292b5a95dbcb2f67695883b (diff)
xc/programs/Xserver/xkb/ddxLoad.c
Bugzilla #2245 (https://bugs.freedesktop.org/show_bug.cgi?id=2245) attachment #1649 (https://bugs.freedesktop.org/attachment.cgi?id=1649): cleanup the generation of xkbcomp command lines. Allocate them dynamicly and remove unmaintainable length calculation.
Diffstat (limited to 'xkb')
-rw-r--r--xkb/ddxList.c34
-rw-r--r--xkb/ddxLoad.c59
2 files changed, 33 insertions, 60 deletions
diff --git a/xkb/ddxList.c b/xkb/ddxList.c
index c58ec46d4..6a070f8a9 100644
--- a/xkb/ddxList.c
+++ b/xkb/ddxList.c
@@ -131,7 +131,7 @@ XkbDDXListComponent( DeviceIntPtr dev,
XkbSrvListInfoPtr list,
ClientPtr client)
{
-char *file,*map,*tmp,buf[PATH_MAX*4];
+char *file,*map,*tmp,*buf=NULL;
FILE *in;
Status status;
int rval;
@@ -162,19 +162,15 @@ char tmpname[PATH_MAX];
(void) mktemp(tmpname);
#endif
if (XkbBaseDirectory!=NULL) {
- if (strlen(XkbBaseDirectory)+strlen(componentDirs[what])+6 > PATH_MAX)
- return BadImplementation;
if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
- sprintf(buf,"%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
+ buf = Xprintf("%s/%s.dir",XkbBaseDirectory,componentDirs[what]);
in= fopen(buf,"r");
+ xfree (buf);
+ buf = NULL;
}
if (!in) {
haveDir= False;
- if (strlen(XkbBaseDirectory)*2+strlen(componentDirs[what])
- +W32_tmplen
- +(xkbDebugFlags>9?2:1)+strlen(file)+35 > PATH_MAX)
- return BadImplementation;
- sprintf(buf,
+ buf = Xprintf(
"'%s/xkbcomp' '-R%s/%s' -w %ld -l -vlfhpR '%s'" W32_tmparg,
XkbBaseDirectory,XkbBaseDirectory,componentDirs[what],(long)
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
@@ -183,18 +179,15 @@ char tmpname[PATH_MAX];
}
}
else {
- if (strlen(XkbBaseDirectory)+strlen(componentDirs[what])+6 > PATH_MAX)
- return BadImplementation;
if ((list->pattern[what][0]=='*')&&(list->pattern[what][1]=='\0')) {
- sprintf(buf,"%s.dir",componentDirs[what]);
+ buf = Xprintf("%s.dir",componentDirs[what]);
in= fopen(buf,"r");
+ xfree (buf);
+ buf = NULL;
}
if (!in) {
haveDir= False;
- if (strlen(componentDirs[what]) + W32_tmplen
- +(xkbDebugFlags>9?2:1)+strlen(file)+29 > PATH_MAX)
- return BadImplementation;
- sprintf(buf,
+ buf = Xprintf(
"xkbcomp -R%s -w %ld -l -vlfhpR '%s'" W32_tmparg,
componentDirs[what],(long)
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:xkbDebugFlags)),
@@ -218,7 +211,14 @@ char tmpname[PATH_MAX];
#endif
}
if (!in)
+ {
+ if (buf != NULL)
+ xfree (buf);
+#ifdef WIN32
+ unlink(tmpname);
+#endif
return BadImplementation;
+ }
list->nFound[what]= 0;
while ((status==Success)&&((tmp=fgets(buf,PATH_MAX,in))!=NULL)) {
unsigned flags;
@@ -272,6 +272,8 @@ char tmpname[PATH_MAX];
fclose(in);
unlink(tmpname);
#endif
+ if (buf != NULL)
+ xfree (buf);
return status;
}
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c
index 832f6b8d0..906715a2b 100644
--- a/xkb/ddxLoad.c
+++ b/xkb/ddxLoad.c
@@ -193,7 +193,7 @@ XkbDDXCompileNamedKeymap( XkbDescPtr xkb,
char * nameRtrn,
int nameRtrnLen)
{
-char cmd[PATH_MAX*4],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
+char *cmd = NULL,file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
if (names->keymap==NULL)
return False;
@@ -225,17 +225,7 @@ char cmd[PATH_MAX*4],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
if (xkbbasedir[i]=='/') xkbbasedir[i]='\\';
#endif
- if (strlen(xkbbasedir)*2+(xkbDebugFlags>9?2:1)
- +(map?strlen(map)+3:0)+strlen(PRE_ERROR_MSG)
- +strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
- +strlen(file)+strlen(xkm_output_dir)
- +strlen(outFile)+59 > PATH_MAX)
- {
- ErrorF("compiler command for keymap (%s) exceeds max length\n",
- names->keymap);
- return False;
- }
- sprintf(cmd,"\"%s" PATHSEPARATOR "xkbcomp\" -w %d \"-R%s\" -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"",
+ cmd = Xprintf("\"%s" PATHSEPARATOR "xkbcomp\" -w %d \"-R%s\" -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"",
xkbbasedir,
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
xkbbasedir,(map?"-m ":""),(map?map:""),
@@ -243,16 +233,7 @@ char cmd[PATH_MAX*4],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
xkm_output_dir,outFile);
}
else {
- if ((xkbDebugFlags>9?2:1)+(map?strlen(map)+3:0)+strlen(PRE_ERROR_MSG)
- +strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
- +strlen(file)+strlen(xkm_output_dir)
- +strlen(outFile)+51 > PATH_MAX)
- {
- ErrorF("compiler command for keymap (%s) exceeds max length\n",
- names->keymap);
- return False;
- }
- sprintf(cmd,"xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"",
+ cmd = Xprintf("xkbcomp -w %d -xkm %s%s -em1 %s -emp %s -eml %s keymap/%s \"%s%s.xkm\"",
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
(map?"-m ":""),(map?map:""),
PRE_ERROR_MSG,ERROR_PREFIX,POST_ERROR_MSG1,file,
@@ -274,6 +255,8 @@ char cmd[PATH_MAX*4],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
}
if (outFile!=NULL)
_XkbFree(outFile);
+ if (cmd!=NULL)
+ xfree(cmd);
return True;
}
#ifdef DEBUG
@@ -281,6 +264,8 @@ char cmd[PATH_MAX*4],file[PATH_MAX],xkm_output_dir[PATH_MAX],*map,*outFile;
#endif
if (outFile!=NULL)
_XkbFree(outFile);
+ if (cmd!=NULL)
+ xfree(cmd);
return False;
}
@@ -293,7 +278,8 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb,
int nameRtrnLen)
{
FILE * out;
-char buf[PATH_MAX*4],keymap[PATH_MAX],xkm_output_dir[PATH_MAX];
+char *buf = NULL, keymap[PATH_MAX],xkm_output_dir[PATH_MAX];
+
#ifdef WIN32
char tmpname[PATH_MAX];
#endif
@@ -332,17 +318,7 @@ char tmpname[PATH_MAX];
if (xkbbasedir[i]=='/') xkbbasedir[i]='\\';
#endif
- if (strlen(xkbbasedir)*2+(xkbDebugFlags>9?2:1)
- +strlen(PRE_ERROR_MSG)+strlen(ERROR_PREFIX)
- +strlen(POST_ERROR_MSG1)+strlen(xkm_output_dir)
- +strlen(xkmfile)
- +strlen(keymap)+53 > PATH_MAX)
- {
- ErrorF("compiler command for keymap (%s) exceeds max length\n",
- names->keymap);
- return False;
- }
- sprintf(buf,
+ buf = Xprintf(
"\"%s" PATHSEPARATOR "xkbcomp\" -w %d \"-R%s\" -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"",
xkbbasedir,
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
@@ -356,16 +332,7 @@ char tmpname[PATH_MAX];
#else
char *xkmfile = tmpname;
#endif
- if ((xkbDebugFlags>9?2:1)+strlen(PRE_ERROR_MSG)
- +strlen(ERROR_PREFIX)+strlen(POST_ERROR_MSG1)
- +strlen(xkmfile)
- +strlen(xkm_output_dir)+strlen(keymap)+45 > PATH_MAX)
- {
- ErrorF("compiler command for keymap (%s) exceeds max length\n",
- names->keymap);
- return False;
- }
- sprintf(buf,
+ buf = Xprintf(
"xkbcomp -w %d -xkm \"%s\" -em1 %s -emp %s -eml %s \"%s%s.xkm\"",
((xkbDebugFlags<2)?1:((xkbDebugFlags>10)?10:(int)xkbDebugFlags)),
xkmfile,
@@ -427,6 +394,8 @@ char tmpname[PATH_MAX];
#endif
}
#endif
+ if (buf != NULL)
+ xfree (buf);
return True;
}
#ifdef DEBUG
@@ -449,6 +418,8 @@ char tmpname[PATH_MAX];
#endif
if (nameRtrn)
nameRtrn[0]= '\0';
+ if (buf != NULL)
+ xfree (buf);
return False;
}