aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2019-06-21 10:57:09 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2019-06-22 11:30:54 +0200
commit054e906f6059366150bb7426973542203c8a0e4c (patch)
tree2d8a0cd3f269ea07658f24cfb7d68f4c01202016
parent2070891cb85c5229dc81661ecf424df57134833a (diff)
downloadnx-libs-054e906f6059366150bb7426973542203c8a0e4c.tar.gz
nx-libs-054e906f6059366150bb7426973542203c8a0e4c.tar.bz2
nx-libs-054e906f6059366150bb7426973542203c8a0e4c.zip
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: Alan Coopersmith <alan.coopersmith@oracle.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r--nx-X11/programs/Xserver/xkb/ddxLoad.c21
-rw-r--r--nx-X11/programs/Xserver/xkb/maprules.c3
2 files changed, 12 insertions, 12 deletions
diff --git a/nx-X11/programs/Xserver/xkb/ddxLoad.c b/nx-X11/programs/Xserver/xkb/ddxLoad.c
index 306a3530f..bff69196f 100644
--- a/nx-X11/programs/Xserver/xkb/ddxLoad.c
+++ b/nx-X11/programs/Xserver/xkb/ddxLoad.c
@@ -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;
diff --git a/nx-X11/programs/Xserver/xkb/maprules.c b/nx-X11/programs/Xserver/xkb/maprules.c
index af6c112fe..6bc7e4022 100644
--- a/nx-X11/programs/Xserver/xkb/maprules.c
+++ b/nx-X11/programs/Xserver/xkb/maprules.c
@@ -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)