From patchwork Mon Oct 29 04:17:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlos Santos X-Patchwork-Id: 990045 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=datacom.com.br Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42k1Y03KDbz9s8F for ; Mon, 29 Oct 2018 15:17:54 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 1176710087; Mon, 29 Oct 2018 05:17:51 +0100 (CET) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from mail.datacom.com.br (mx.datacom.ind.br [177.66.5.10]) by helium.openadk.org (Postfix) with ESMTPS id 8E70410087 for ; Mon, 29 Oct 2018 05:17:49 +0100 (CET) Received: from mail.datacom.com.br (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTPS id 5B05C1BA07A9 for ; Mon, 29 Oct 2018 01:18:10 -0300 (-03) Received: from localhost (localhost [127.0.0.1]) by mail.datacom.com.br (Postfix) with ESMTP id 4CAC01BA07A4 for ; Mon, 29 Oct 2018 01:18:10 -0300 (-03) Received: from mail.datacom.com.br ([127.0.0.1]) by localhost (mail.datacom.com.br [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id AQoRG2JXNtU3 for ; Mon, 29 Oct 2018 01:18:10 -0300 (-03) Received: from p7-1130br.casantos.org (unknown [201.86.222.47]) by mail.datacom.com.br (Postfix) with ESMTPSA id 0F3FC1BA07A3 for ; Mon, 29 Oct 2018 01:18:09 -0300 (-03) From: Carlos Santos To: devel@uclibc-ng.org Date: Mon, 29 Oct 2018 01:17:38 -0300 Message-Id: <20181029041738.31984-1-casantos@datacom.com.br> X-Mailer: git-send-email 2.17.1 Subject: [uclibc-ng-devel] [PATCH] mkostemp64: clear flags, as mkostemp does X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" This should have been made in commit 9649721950 but was forgotten. Signed-off-by: Carlos Santos --- Test: $ cat test.c #include #include #include #include #include #include #include void fatal(int n) { fprintf(stderr, "fatal[%d]: %s\n", n, strerror(errno)); exit(1); } int main(int argc, char *argv[]) { FILE *f; int cur_mode; char template[64]; strncpy(template, argc > 1 ? argv[1] : "testXXXXXX", 63); umask(077); printf("main[1]: %s, %07o\n", template, O_WRONLY|O_CLOEXEC); int fd = mkostemp(template, O_WRONLY|O_CLOEXEC); if (fd < 0) { fatal(1); } cur_mode = fcntl(fd, F_GETFL); printf("main[2]: %s, %07o\n", template, cur_mode); printf("main[3]: %d, %s\n", fd, "we"); f = fdopen(fd, "we"); if (!f) { fatal(2); } if (fclose(f) == EOF) { fatal(3); } return 0; } $ x86_64-buildroot-linux-uclibc-cc -Wall -Werror -D_GNU_SOURCE \ -o mkostemp-test test.c $ x86_64-buildroot-linux-uclibc-cc -Wall -Werror -D_GNU_SOURCE \ -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 \ -o mkostemp-test-large test.c [ copy executables to target device (qemu, in this case) ] Without patch: # mkostemp-test main[1]: testXXXXXX, 2000001 random: fast init done main[2]: testIPn9UR, 0100002 main[3]: 3, we # mkostemp-test-large main[1]: testXXXXXX, 2000001 main[2]: testiXRydb, 0100003 main[3]: 3, we fatal[2]: Invalid argument With patch: # mkostemp-test main[1]: testXXXXXX, 2000001 main[2]: testcVhbXs, 0100002 main[3]: 3, we # mkostemp-test-large main[1]: testXXXXXX, 2000001 main[2]: testDAulBF, 0100002 main[3]: 3, we --- Change-Id: I07226e166de1d8d7b8398cd54939ad43768352cf --- libc/stdlib/mkostemp64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/stdlib/mkostemp64.c b/libc/stdlib/mkostemp64.c index aa9736cd6..f4674bb0c 100644 --- a/libc/stdlib/mkostemp64.c +++ b/libc/stdlib/mkostemp64.c @@ -15,9 +15,9 @@ License along with the GNU C Library; if not, see . */ -#include #include #include +#include #include "../misc/internals/tempname.h" /* Generate a unique temporary file name from TEMPLATE. @@ -27,6 +27,7 @@ int mkostemp64 (char *template, int flags) { + flags -= flags & O_ACCMODE; /* Remove O_RDONLY, O_WRONLY, and O_RDWR. */ return __gen_tempname (template, __GT_BIGFILE, flags | O_LARGEFILE, 0, S_IRUSR | S_IWUSR); }