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: 443708 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EECE614010F for ; Thu, 26 Feb 2015 10:43:28 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=sourceware.org header.i=@sourceware.org header.b=Yb2Rjbmb; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; q= dns; s=default; b=OqECcQyQYBY41GwcqXcg7KPZ+/MNZdQ+5Z9gzFRiLTFq0U iUEiroOu4hSpRNO4fRPfd4uCInl8VIUSl8IpbvGQ7JpriYuZs3sRTGiiAMY71Fz7 ITp6igSLx/Pb1vGY/sSv1+XoZ1R5zt2CP2Zt8yCqObeY60ARf+Yi77xjgKiVY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:mime-version:content-type :content-transfer-encoding:from:to:subject:message-id:date; s= default; bh=ESdUtErorS7GhROIhB5l2oPCBls=; b=Yb2RjbmbzZKRKMc7PgdJ /79+OdQOc5Re87jOeVYUBD5s+Fsdk/JQYXBqx5aLye8cTTb6Phv5OQkowqFCQ8aN fFhxseL9l4VCikER+X/KuC5aLAnkEuWnL/btYvwwXwdsvoNH+9EI9iwHms53NKDi DvKA5nD+1H9BVTfUR6zsNvo= 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] == '/');