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

Message ID 20150225234316.4AA222C3ADB@topped-with-meat.com
State New
Headers show

Commit Message

Roland McGrath Feb. 25, 2015, 11:43 p.m. UTC
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.

Patch
diff mbox

--- 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] == '/');