diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-02-13 21:36:02 -0800 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-02-15 10:35:38 +1000 |
commit | a4a2e814d5d0e6152307a301eda1d6fc1c555aaa (patch) | |
tree | a58a86cc537d53622ae63a25941005bac13e70ba /xkb | |
parent | ea1ffd3e60bdcedbec5a6f28929f8677bf45d450 (diff) |
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>
Diffstat (limited to 'xkb')
-rw-r--r-- | xkb/ddxLoad.c | 21 | ||||
-rw-r--r-- | xkb/maprules.c | 3 |
2 files changed, 12 insertions, 12 deletions
diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index 51b577725..9686ea85d 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -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) { diff --git a/xkb/maprules.c b/xkb/maprules.c index c683c0d4f..0c91cdc20 100644 --- a/xkb/maprules.c +++ b/xkb/maprules.c @@ -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) |