From patchwork Mon Jun 3 13:34:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 1109275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-102405-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Wtcv25O+"; dkim-atps=neutral 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 45Hbd76gP8z9sN6 for ; Mon, 3 Jun 2019 23:34:35 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=tEEe7p4NHeJ8I0dXNWsBpG5xDdFQx mERf9tQ35NQmYfmN8hE3lCFtyLTBiXpmm1URVbIKaBASXNlG3+ftIRP2h7hvn+pO m994237QDKVNreqy7UwT6l8GRYu0PGDfiuJd9MTukqiEK/y44Cc6yKWoJ059zA9A T5N3Xged7ryjWc= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=Q7G5GLNOiZBosvjOK5IbVsHm30Q=; b=Wtc v25O+dhoiR6IQ3U9kCgWg3gWj81qc+E5ldMLMtNcWBy37JWYQTGWG7Vpd0YdTlRN 62b+mJ8MfloKuBWC1NJ3jcdlezGRpyePa0eiSgHinpZkDdDpKHv469sTnZ/ii4VM ZofPYXT2tE7eXABnailyYex19OGlbw4rOKge/1pM= Received: (qmail 130949 invoked by alias); 3 Jun 2019 13:34:30 -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 130941 invoked by uid 89); 3 Jun 2019 13:34:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=HX-Languages-Length:1487 X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] libio: freopen of default streams crashes in old programs [BZ #24632] Date: Mon, 03 Jun 2019 15:34:26 +0200 Message-ID: <8736kqaj31.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 As seen with very old i386 GCC binaries. 2019-06-03 Florian Weimer [BZ #24632] * libio/libioP.h (_IO_JUMPS_FUNC_UPDATE): New macro. * libio/freopen.c (freopen): Use it. diff --git a/libio/freopen.c b/libio/freopen.c index 17b00258cd..82e39f5028 100644 --- a/libio/freopen.c +++ b/libio/freopen.c @@ -62,7 +62,7 @@ freopen (const char *filename, const char *mode, FILE *fp) to the old libio may be passed into shared C library and wind up here. */ _IO_old_file_close_it (fp); - _IO_JUMPS_FILE_plus (fp) = &_IO_old_file_jumps; + _IO_JUMPS_FUNC_UPDATE (fp, &_IO_old_file_jumps); result = _IO_old_file_fopen (fp, gfilename, mode); } else diff --git a/libio/libioP.h b/libio/libioP.h index 66afaa8968..f17c6e68e4 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -108,9 +108,14 @@ (IO_validate_vtable \ (*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \ + (THIS)->_vtable_offset))) +# define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \ + (*(const struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \ + + (THIS)->_vtable_offset) = (VTABLE)) # define _IO_vtable_offset(THIS) (THIS)->_vtable_offset #else # define _IO_JUMPS_FUNC(THIS) (IO_validate_vtable (_IO_JUMPS_FILE_plus (THIS))) +# define _IO_JUMPS_FUNC_UPDATE(THIS, VTABLE) \ + (_IO_JUMPS_FILE_plus (THIS) = (VTABLE)) # define _IO_vtable_offset(THIS) 0 #endif #define _IO_WIDE_JUMPS_FUNC(THIS) _IO_WIDE_JUMPS(THIS)