From patchwork Tue May 19 15:26:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 473960 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 659E11400B7 for ; Wed, 20 May 2015 01:27:48 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sourceware.org header.i=@sourceware.org header.b=f9JDqxk5; 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:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=FkNHrPH25qHDFKGfCwb/y5Q31mLjF 6I2wVdkxIGvVnBAtHj8fhhhhz6NR6Ia2lGdXg+FQXsklszPTogZsx7pIT25xZHAA wKNPy0XOdi06l0706fsRSC/0aOafM/8xmvnek43Tq4i16KotEiaRQTbef8BlfHGH gs5Ex2tG+LmrRU= 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:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=xnUomRr3EFx80OddaREyt8lHA5M=; b=f9J Dqxk5/OlQIbyxZ1YqzFzUk1mHqIO7yfG9n+tuqz3yHQ+Zk7YP95SYGqDW4EZLB2n trJeKCDhxcChXh9zQJ191g2gbXOF2AdHHHA4pBuyC8IWP8hcpdALNkeEUpqADfK0 Nb5vxInIPFae1OYXTEFBEZmxwjtLWBehPHwnd2dM= Received: (qmail 30251 invoked by alias); 19 May 2015 15:27:36 -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 30183 invoked by uid 89); 19 May 2015 15:27:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Date: Tue, 19 May 2015 17:26:46 +0200 From: Cyril Hrubis To: libc-alpha@sourceware.org Subject: sbrk() does not set errno on overflow Message-ID: <20150519152646.GA2052@rei.suse.de> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi! I've been looking at LTP test failures on x86_64 and 32bit test binaries and I've found that testcase for sbrk() fails. What the test does is to call sbrk() repeatedly until it fails and checks that the return value is -1 and errno set to ENOMEM. Now this works fine on x86_64 because we hit ENOMEM from kernel brk() before address space overflows. But with 32bit binary we hit overflow check in glibc which does not seem to set errno. Here is what I would do for a fix, I will create a proper patch with ChangeLog etc. if this change is OK for glibc. diff --git a/misc/sbrk.c b/misc/sbrk.c index 87b5472..7ff3921 100644 --- a/misc/sbrk.c +++ b/misc/sbrk.c @@ -50,8 +50,10 @@ __sbrk (intptr_t increment) if ((increment > 0 ? ((uintptr_t) oldbrk + (uintptr_t) increment < (uintptr_t) oldbrk) : ((uintptr_t) oldbrk < (uintptr_t) -increment)) - || __brk (oldbrk + increment) < 0) + || __brk (oldbrk + increment) < 0) { + __set_errno (ENOMEM); return (void *) -1; + } return oldbrk; }