From patchwork Wed Feb 7 09:37:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sven Linker X-Patchwork-Id: 1896071 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=B5xcNHYl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=uclibc-ng.org (client-ip=2a00:1828:2000:679::23; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=patchwork.ozlabs.org) Received: from helium.openadk.org (helium.openadk.org [IPv6:2a00:1828:2000:679::23]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TVFQX3KJtz23gD for ; Wed, 7 Feb 2024 20:37:40 +1100 (AEDT) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id B56F135210B5; Wed, 7 Feb 2024 10:37:32 +0100 (CET) Authentication-Results: helium.openadk.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernkonzept.com header.i=@kernkonzept.com header.a=rsa-sha256 header.s=mx1 header.b=B5xcNHYl; dkim-atps=neutral Received: from mx.kernkonzept.com (serv1.kernkonzept.com [159.69.200.6]) by helium.openadk.org (Postfix) with ESMTPS id D2E1235205A0 for ; Wed, 7 Feb 2024 10:37:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kernkonzept.com; s=mx1; h=MIME-Version:Content-Type:References:In-Reply-To: Date:To:From:Subject:Message-ID:Content-Transfer-Encoding:Cc:Reply-To: Content-ID:Content-Description; bh=kEUGAzfym8sIOLxvy6nCke6XfBIyp/g1xGi1SyQ0rm8=; b=B5xcNHYlP6o6fIhoqSC5RG5iDg fAqUGk4Cu9RhCgtk6Y5eu1B41SdwBPtrGnOoFVhiQNPsyBg6eEp7uSDyXFnZ9TgGL3L6sWDl69Rcr fFFnob+iYNao8D5Q66aZ4yqd0q0vXeoE+gPTXn+yJ05eWBe9tSMWpdQ49etH9ZtJ7h3NLKzzvtuP/ 2u7TWbtcEPrp+JEL61TTz+nvo0NkwSfoQWBrxcOz8GT07mYkJTBNWxtxXJuFvaRTAsFIAan4EGq/A vS7PJCNSHrvy7ENShUe8Lm0k2LgeQwvaHGz3D6x3n58CZPlLNew+aCVWlmx7AfO6Y1+OdPoEecL99 jEON614A==; Received: from [10.22.3.197] by mx.kernkonzept.com with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) id 1rXeMt-0057iC-0P for devel@uclibc-ng.org; Wed, 07 Feb 2024 10:37:23 +0100 Message-ID: From: Sven Linker To: devel@uclibc-ng.org Date: Wed, 07 Feb 2024 10:37:22 +0100 In-Reply-To: References: <32e1d729bbca378b05c4205871a019d517c15da1.camel@kernkonzept.com> Autocrypt: addr=sven.linker@kernkonzept.com; prefer-encrypt=mutual; keydata=mDMEY4XAPhYJKwYBBAHaRw8BAQdAj2pxXXDZ11J7Cabgcn2SAlJv4DZCqunP9OSo6bMcgMm0KVN2ZW4gTGlua2VyIDxzdmVuLmxpbmtlckBrZXJua29uemVwdC5jb20+iJMEExYKADsWIQTc6ToCnlWzy3N5PE6wKZMAQVa94QUCY4XAPgIbAQULCQgHAgIiAgYVCgkICwIEFgIDAQIeBwIXgAAKCRCwKZMAQVa94afZAQCSTq8YKb23wtsxRC0m+dDMUx3sxThhMhbqeMG2wSd6PgD8CwOxBldSZmnRwvuM9kcpB/rIqAcqfzs/Fmh7JlVnFAa4MwRjhcDHFgkrBgEEAdpHDwEBB0D7PWcMOHkVLiSGOQry7+7JwGTJtO5u8xPmHBouKAoTDoj1BBgWCgAmAhsCFiEE3Ok6Ap5Vs8tzeTxOsCmTAEFWveEFAmV2sfEFCQPSJKoAgXYgBBkWCgAdFiEEy6hAd9e95ZL26ctSN/5nXwCUKuUFAmOFwMcACgkQN/5nXwCUKuUhWQEAgXoX3R6P4YP614WH2umYdDmRhVAmEGbWLbtYvrPyGbcA+gJDGiQprHY6Nba4P8t6DrIUWzdvwPB43IVJYcKpYacJCRCwKZMAQVa94XylAQCH3DP8ZxIF8SJn52NXvzMzRDHlcu89eQ6C9VKJH/XQ1AEAugUFutLB8uLrK8RiVMq6JERbKaidHnZx1C7su8lmHw64OARjhcD7EgorBgEEAZdVAQUBAQdA5wRHGy6fFqZGwIUlAlaHGX2MOzqauwUb7mv75eSCEwkDAQgHiH4EGBYKACYCGwwWIQTc6ToCnlWzy3N5PE6wKZMAQVa94QUCZXax8QUJA9IkdgAKCRCwKZMAQVa94c4eAP9Y5Br/hPEJkBioXiBhRMtNvjztw1wrOUbMbbkUHT6NiQEA1tzVNCznSmci+1tCOXLlnjS70SnarOKKxqmS4GBR5gu4MwRjhcEdFgkrB gEEAdpHDwEBB0C2waP3fC20vFSsnSLF+vQHKA9sc9u0mzFhBJ3vJYugF4h+BBgWCgAmAhsgFiEE3Ok6Ap5Vs8tzeTxOsCmTAEFWveEFAmV2sfEFCQPSJFQACgkQsCmTAEFWveG+2wEAy9sq19BMTaJJp4lhY75kW0WzJgeclLfDMCIMjXAtAQAA/3nO+aJLFcM6hRhnufwAIwx6peiqWF9gx4/bTjVdQmAH User-Agent: Evolution 3.50.3 (3.50.3-1.fc39) MIME-Version: 1.0 Message-ID-Hash: Y63FXODRRCMVYUTRQ63CJIYUNKSSQASE X-Message-ID-Hash: Y63FXODRRCMVYUTRQ63CJIYUNKSSQASE X-MailFrom: sven.linker@kernkonzept.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] Re: Possible bug in tempname.c (and its usage)? List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Hi, I'm not sure if this really tests the branch where the issue is, but I am also not able to come up with a simple test myself (since it basically relies on predicting the random instantiation of the template). But this patch should avoid opening the file, if it already exists. Cheers, Sven On Tue, 2024-02-06 at 15:13 +0100, Marius Melzer wrote: > Hi, > > On 31.01.24 11:08, Waldemar Brodkorb wrote: > > do you have a small C test case which might show the failure? > > I unfortunately currently don't have a proper setup to test this, but > I > would expect that this simple loop would deplete all available file > descriptors so that at some point, one can't call "open" anymore: > > #include > > do { >    puts("Still fds available\n"); > } while(!strcmp(mktemp("test"),"")) > > if(open("somefile.txt") < 0) { >    puts("fds are depleted. This should not have happened.\n"); > } > > Best regards, > Marius > diff --git a/libc/misc/internals/tempname.c b/libc/misc/internals/tempname.c index d3a8ccbd8..f9b714a68 100644 --- a/libc/misc/internals/tempname.c +++ b/libc/misc/internals/tempname.c @@ -218,7 +218,8 @@ int attribute_hidden __gen_tempname (char *tmpl, int kind, int flags, /* Give up now. */ return -1; } else - fd = 0; + /* File already exists, so return with non-zero value */ + return -1; } case __GT_FILE: fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | flags, mode);