[COMMITTED PATCH] Don't crash in iconv setup when getcwd fails.

Roland McGrath roland@hack.frob.com
Wed Feb 25 23:43:00 GMT 2015


When __getcwd fails, __gconv_get_path will call strlen on a null pointer.
This fix at least delays the crash until the cwd is actually needed (if it
ever is).  This makes some iconv/ tests work in a circumstance where getcwd
fails.


Thanks,
Roland


2015-02-25  Roland McGrath  <roland@hack.frob.com>

	* iconv/gconv_conf.c (__gconv_get_path): Don't crash if __getcwd
	returns a null pointer.

--- a/iconv/gconv_conf.c
+++ b/iconv/gconv_conf.c
@@ -468,7 +468,7 @@ __gconv_get_path (void)
 				":", 1),
 		     default_gconv_path, sizeof (default_gconv_path));
 	  cwd = __getcwd (NULL, 0);
-	  cwdlen = strlen (cwd);
+	  cwdlen = __glibc_unlikely (cwd == NULL) ? 0 : strlen (cwd);
 	}
       assert (default_gconv_path[0] == '/');
 



More information about the Libc-alpha mailing list