[PATCH:libX11 02/22] lcfile: skip over any null entries in args list

Alan Coopersmith alan.coopersmith at oracle.com
Mon Aug 12 00:03:53 PDT 2013


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 <alan.coopersmith at oracle.com>
---
 src/xlibi18n/lcFile.c |   35 +++++++++++++++--------------------
 1 file changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/xlibi18n/lcFile.c b/src/xlibi18n/lcFile.c
index 61a14e7..03ece75 100644
--- a/src/xlibi18n/lcFile.c
+++ b/src/xlibi18n/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);
-- 
1.7.9.2



More information about the xorg-devel mailing list