Commit a4a2e814 authored by Alan Coopersmith's avatar Alan Coopersmith Committed by Peter Hutterer

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

Signed-off-by: Alan Coopersmith's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Daniel Stone's avatarDaniel Stone <daniel@fooishbar.org>
parent ea1ffd3e
......@@ -303,15 +303,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;
......@@ -388,11 +389,11 @@ XkbRF_RulesPtr rules;
if (!rules_name)
return FALSE;
if (strlen(XkbBaseDirectory) + strlen(rules_name) + 8 > PATH_MAX) {
if (snprintf(buf, PATH_MAX, "%s/rules/%s", XkbBaseDirectory, rules_name)
>= PATH_MAX) {
LogMessage(X_ERROR, "XKB: Rules name is too long\n");
return FALSE;
}
sprintf(buf,"%s/rules/%s", XkbBaseDirectory, rules_name);
file = fopen(buf, "r");
if (!file) {
......
......@@ -945,9 +945,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