From patchwork Tue Aug 6 06:16:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 95344 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35A81385C6C8 for ; Tue, 6 Aug 2024 06:17:06 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 220EA3857000 for ; Tue, 6 Aug 2024 06:16:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 220EA3857000 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 220EA3857000 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722924985; cv=none; b=HnpQZsYzA8DkMw7ijMOYJSRd3wlut2BTLES2udJosfDwt7iGLmEeX1lynp8DkRSp64tCrgyFW9r4hDvjv4Us5D99LGyZHAtACx5jj2L44s7FJpFYqm0M5T68kVWuj6X4JFUbyxDqY6OYaY+8+wfhN4hAcB8kkaJVj4unaBrI9hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722924985; c=relaxed/simple; bh=0k0HZjnJyeXIqVluUWXtWRjaANzQ2jkBcwohl/TTZeE=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=dNGYPAAnhUd1ZZRqi9Rfo1V6nr3XjnU67W5KYpfHG0+S2zGBi2+xJtS1ianHHx5zzmglGYBcBc61I9qO6r8eJc+4j3UEbXu8OwkbLhFghy4diz4nKHmGjpLLCO+KUaJaTV6Q1AdPzSfJOaX2TvCzF6KCEWLglZo4UDfBg1W92zY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722924981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zNq3rmR+2pnobwikdOUYj7G7b5vX0DY2crE801rbjlI=; b=bYn0TiYINVmRvASVC2WC2ByaSudHSPQEExMi+vGQhna8ZLxIgJhLibueWf1KhiH5Z4rG7I WfYeC6zDXUm65lOdEqJE5Fp9mtiK35ji8JCIBpx+mq4NAAsSkQ7u16Tz5KPhfTW4jgz2SJ A91CjNfTH6c/L9QJtGdDn1qOjPybdO0= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-mdlmcLRuM6-6C5PVtjba3w-1; Tue, 06 Aug 2024 02:16:19 -0400 X-MC-Unique: mdlmcLRuM6-6C5PVtjba3w-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CC12E195609F for ; Tue, 6 Aug 2024 06:16:18 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.45.224.40]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EA6601955D42 for ; Tue, 6 Aug 2024 06:16:17 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH v2 2/7] iconv: Do not use mmap in iconv (the program) (bug 17703) In-Reply-To: Message-ID: <2a6a76d5d6d1fdf571f65e7e12f42eedb571d0a4.1722924862.git.fweimer@redhat.com> References: X-From-Line: 2a6a76d5d6d1fdf571f65e7e12f42eedb571d0a4 Mon Sep 17 00:00:00 2001 Date: Tue, 06 Aug 2024 08:16:14 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org On current systems, very large files are needed before mmap becomes beneficial. Simplify the implementation. This exposed that inptr was not initialized correctly in process_fd. Handling multiple input files resulted in EFAULT in read because a null pointer was passed. This could be observed previously if an input file was not mappable and was reported as bug 17703. Reviewed-by: DJ Delorie --- iconv/iconv_prog.c | 42 +----------------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/iconv/iconv_prog.c b/iconv/iconv_prog.c index a765b1af21..88a928557e 100644 --- a/iconv/iconv_prog.c +++ b/iconv/iconv_prog.c @@ -31,9 +31,6 @@ #include #include #include -#ifdef _POSIX_MAPPED_FILES -# include -#endif #include #include #include "iconv_prog.h" @@ -253,10 +250,6 @@ conversions from `%s' and to `%s' are not supported"), else do { -#ifdef _POSIX_MAPPED_FILES - struct stat64 st; - char *addr; -#endif int fd, ret; if (verbose) @@ -276,39 +269,6 @@ conversions from `%s' and to `%s' are not supported"), } } -#ifdef _POSIX_MAPPED_FILES - /* We have possibilities for reading the input file. First try - to mmap() it since this will provide the fastest solution. */ - if (fstat64 (fd, &st) == 0 - && ((addr = mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, - fd, 0)) != MAP_FAILED)) - { - /* Yes, we can use mmap(). The descriptor is not needed - anymore. */ - if (close (fd) != 0) - error (EXIT_FAILURE, errno, - _("error while closing input `%s'"), - argv[remaining]); - - ret = process_block (cd, addr, st.st_size, &output, - output_file); - - /* We don't need the input data anymore. */ - munmap ((void *) addr, st.st_size); - - if (ret != 0) - { - status = EXIT_FAILURE; - - if (ret < 0) - /* We cannot go on with producing output since it might - lead to problem because the last output might leave - the output stream in an undefined state. */ - break; - } - } - else -#endif /* _POSIX_MAPPED_FILES */ { /* Read the file in pieces. */ ret = process_fd (cd, fd, &output, output_file); @@ -544,7 +504,7 @@ process_fd (iconv_t cd, int fd, FILE **output, const char *output_file) process it in one step. */ static char *inbuf = NULL; static size_t maxlen = 0; - char *inptr = NULL; + char *inptr = inbuf; size_t actlen = 0; while (actlen < maxlen)