From bde3d8b141ff42c1f6828e5ed1467b691e54b253 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Fri, 9 Aug 2013 23:02:12 -0700 Subject: lcfile: skip over any null entries in args list Previous code seemed to assume that printf("%s", NULL) would result in a 0-length string, not "(null)" or similar, but since there's no point looking for files in "(null)/filepath...", instead we just skip over NULL entries in search paths when generating file names. In the *DirName() functions, this effectively just moves the "bail on NULL in arg[i]" check up from the later code that assigned it to targetdir and then bailed if that was NULL. Not sure how there ever could be a NULL in arg[i], given the current implementation of XlcParsePath, but it's easy enough to check once and reject up front instead of on every reference. Signed-off-by: Alan Coopersmith Backported-to-NX-by: Ulrich Sibiller --- nx-X11/lib/X11/lcFile.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'nx-X11') diff --git a/nx-X11/lib/X11/lcFile.c b/nx-X11/lib/X11/lcFile.c index aeaae245d..3b239ff2f 100644 --- a/nx-X11/lib/X11/lcFile.c +++ b/nx-X11/lib/X11/lcFile.c @@ -486,8 +486,11 @@ _XlcFileName( for (i = 0; i < n; ++i) { char buf[PATH_MAX], *name; + if (args[i] == NULL) + continue; + name = NULL; - if ((5 + (args[i] ? strlen (args[i]) : 0) + strlen(cat)) < PATH_MAX) { + if ((5 + strlen(args[i]) + strlen(cat)) < PATH_MAX) { sprintf(buf, "%s/%s.dir", args[i], cat); name = resolve_name(siname, buf, RtoL); } @@ -498,7 +501,7 @@ _XlcFileName( /* supposed to be absolute path name */ file_name = name; } else { - file_name = Xmalloc(2 + (args[i] ? strlen (args[i]) : 0) + + file_name = Xmalloc(2 + strlen(args[i]) + (name ? strlen (name) : 0)); if (file_name != NULL) sprintf(file_name, "%s/%s", args[i], name); @@ -535,8 +538,10 @@ _XlcResolveLocaleName( xlocaledir (dir, PATH_MAX); n = _XlcParsePath(dir, args, NUM_LOCALEDIR); for (i = 0; i < n; ++i) { - if ((2 + (args[i] ? strlen (args[i]) : 0) + - strlen (locale_alias)) < PATH_MAX) { + if (args[i] == NULL) + continue; + + if ((2 + strlen (args[i]) + strlen (locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name (lc_name, buf, LtoR); if (!name) { @@ -633,9 +638,10 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) xlocaledir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + if (args[i] == NULL) + continue; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { + if ((2 + strlen(args[i]) + strlen(locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name(lc_name, buf, LtoR); if (!name) { @@ -653,12 +659,6 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name) /* look at locale.dir */ target_dir = args[i]; - if (!target_dir) { - /* something wrong */ - if (name != lc_name) - Xfree(name); - continue; - } if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { sprintf(buf, "%s/locale.dir", target_dir); target_name = resolve_name(name, buf, RtoL); @@ -731,9 +731,10 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) xlocalelibdir (dir, PATH_MAX); n = _XlcParsePath(dir, args, 256); for (i = 0; i < n; ++i) { + if (args[i] == NULL) + continue; - if ((2 + (args[i] ? strlen(args[i]) : 0) + - strlen(locale_alias)) < PATH_MAX) { + if ((2 + strlen(args[i]) + strlen(locale_alias)) < PATH_MAX) { sprintf (buf, "%s/%s", args[i], locale_alias); name = resolve_name(lc_name, buf, LtoR); if (!name) { @@ -751,12 +752,6 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name) /* look at locale.dir */ target_dir = args[i]; - if (!target_dir) { - /* something wrong */ - if (name != lc_name) - Xfree(name); - continue; - } if ((1 + strlen (target_dir) + strlen("locale.dir")) < PATH_MAX) { sprintf(buf, "%s/locale.dir", target_dir); target_name = resolve_name(name, buf, RtoL); -- cgit v1.2.3