From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19733 invoked from network); 10 Apr 2022 11:07:15 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 10 Apr 2022 11:07:14 -0000 Received: (qmail 20290 invoked by uid 550); 10 Apr 2022 11:07:07 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21518 invoked from network); 9 Apr 2022 22:59:14 -0000 Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="jqYGngjb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1649545140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=372sO1gtMzsVVArk8n9lIXPgvqZMybrAr+YLXzccQiU=; b=jqYGngjb7iayglM5j4ToBmbgLWDy66zeBIIUchuoa4Wj2PkS4h5inKEhjtBPajBlC9h59q cKSR8CoHIzNcVjo1+GbSslYgIkC9gHNnmFMNAt81baFhDu3a2MZaA97Lt1J/tDfAnGipYd Cu8FM5U2mnv2dfUURYbwH9la3WukuVU= From: "Jason A. Donenfeld" To: Rich Felker , musl@lists.openwall.com Cc: "Jason A. Donenfeld" Date: Sun, 10 Apr 2022 00:58:49 +0200 Message-Id: <20220409225851.715796-1-Jason@zx2c4.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v2] getentropy: fail if buffer not completely filled The man page for getentropy says that it either completely succeeds or completely fails, and indeed this is what glibc does. However, musl has a condition where it breaks out of the loop early, yet still returns a success. This patch fixes that by returning a success only if the buffer is completely filled. --- Changes v2->v3: - This gets rid of the ret==0 check like glibc uses. src/misc/getentropy.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/misc/getentropy.c b/src/misc/getentropy.c index 651ea95f..964b8c10 100644 --- a/src/misc/getentropy.c +++ b/src/misc/getentropy.c @@ -6,7 +6,7 @@ int getentropy(void *buffer, size_t len) { - int cs, ret = 0; + int cs, ret; char *pos = buffer; if (len > 256) { @@ -24,10 +24,13 @@ int getentropy(void *buffer, size_t len) } pos += ret; len -= ret; - ret = 0; } pthread_setcancelstate(cs, 0); - return ret; + if (len) { + errno = EIO; + return -1; + } + return 0; } -- 2.35.1