This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[COMMITTED PATCH] Don't crash in iconv setup when getcwd fails.
- From: Roland McGrath <roland at hack dot frob dot com>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Date: Wed, 25 Feb 2015 15:43:16 -0800 (PST)
- Subject: [COMMITTED PATCH] Don't crash in iconv setup when getcwd fails.
- Authentication-results: sourceware.org; auth=none
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] == '/');