Commit 054e906f authored by Ulrich Sibiller's avatar Ulrich Sibiller Committed by Mike Gabriel

xkb: Use snprintf to measure string lengths instead of manual strlen math

commit a4a2e814d5d0e6152307a301eda1d6fc1c555aaa Author: Alan Coopersmith <alan.coopersmith@oracle.com> Date: Sun Feb 13 21:36:02 2011 -0800 xkb: Use snprintf to measure string lengths instead of manual strlen math Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com> Signed-off-by: 's avatarPeter Hutterer <peter.hutterer@who-t.net> Reviewed-by: 's avatarDaniel Stone <daniel@fooishbar.org>
parent 2070891c
......@@ -404,15 +404,16 @@ FILE * file;
&&(!isalpha(xkm_output_dir[0]) || xkm_output_dir[1]!=':')
#endif
) {
if (strlen(XkbBaseDirectory)+strlen(xkm_output_dir)
+strlen(mapName)+6 <= PATH_MAX)
{
sprintf(buf,"%s/%s%s.xkm",XkbBaseDirectory,
xkm_output_dir,mapName);
}
if (snprintf(buf, PATH_MAX, "%s/%s%s.xkm", XkbBaseDirectory,
xkm_output_dir, mapName) >= PATH_MAX)
buf[0] = '\0';
}
else
{
if (snprintf(buf, PATH_MAX, "%s%s.xkm", xkm_output_dir, mapName)
>= PATH_MAX)
buf[0] = '\0';
}
else if (strlen(xkm_output_dir)+strlen(mapName)+5 <= PATH_MAX)
sprintf(buf,"%s%s.xkm",xkm_output_dir,mapName);
if (buf[0] != '\0')
file= fopen(buf,"rb");
else file= NULL;
......@@ -505,9 +506,9 @@ XkbRF_RulesPtr rules;
sprintf(buf,"rules/%s",rules_name);
}
else {
if (strlen(XkbBaseDirectory)+strlen(rules_name)+8 > PATH_MAX)
if (snprintf(buf, PATH_MAX, "%s/rules/%s", XkbBaseDirectory, rules_name)
>= PATH_MAX)
return False;
sprintf(buf,"%s/rules/%s",XkbBaseDirectory,rules_name);
}
if ((file= fopen(buf,"r"))==NULL)
return False;
......
......@@ -953,9 +953,8 @@ Bool ok;
if ((!base)||(!rules))
return False;
if (locale) {
if (strlen(base)+strlen(locale)+2 > PATH_MAX)
if (snprintf(buf, PATH_MAX, "%s-%s", base, locale) >= PATH_MAX)
return False;
sprintf(buf,"%s-%s", base, locale);
}
else {
if (strlen(base)+1 > PATH_MAX)
......
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