From patchwork Wed Feb 25 23:43:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland McGrath X-Patchwork-Id: 5288 Received: (qmail 9455 invoked by alias); 25 Feb 2015 23:43:22 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 9407 invoked by uid 89); 25 Feb 2015 23:43:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: topped-with-meat.com MIME-Version: 1.0 From: Roland McGrath To: "GNU C. Library" Subject: [COMMITTED PATCH] Don't crash in iconv setup when getcwd fails. Message-Id: <20150225234316.4AA222C3ADB@topped-with-meat.com> Date: Wed, 25 Feb 2015 15:43:16 -0800 (PST) X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=SvUDtp+0 c=1 sm=1 tr=0 a=WkljmVdYkabdwxfqvArNOQ==:117 a=14OXPxybAAAA:8 a=kj9zAlcOel0A:10 a=hOe2yjtxAAAA:8 a=0qIzLi1IA6vf_TvLBG8A:9 a=CjuIK1q_8ugA:10 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 * 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] == '/');