From nobody Sun Apr 30 06:58:21 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q8HHK6Pczz48sMx; Sun, 30 Apr 2023 06:58:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q8HHK47x1z3PS2; Sun, 30 Apr 2023 06:58:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682837901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pHIz+tl8gXRdHh/w8S+IcFFIvTN1bJ2DyWU3kR/zD9Y=; b=VahJKRQwgj1CitdfShO6vbRMV0b3ep0odjnyiWSh3psCbJX6E/rVQrd9ftpP/hqXTFYleW R2A2LnNm1JoQ2qxn2Q+vMnrM8ZmTlY2BxQ3xvqv2T8hYXaW2dC0dAXWIiltd2XMdkYm4Qp 88GayZ6HLLr0cmtpzV4D02bk0VH3QIbGNij/ub6VyJtiVrCQDthF3A6oA/IaLc0L8m1fdu X+I1dvA5td2DlEyern4cZM8sgbZLR9j+Qn4Zs3pDnWRtfbVqwEo4r2DOZ2Ts04lv0byEqE IdktqTX/MMu7HN8f46FmJgACtlre0aCF8OYM8GbgZf2jXAtJ3ci6HUqoSGGfBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682837901; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pHIz+tl8gXRdHh/w8S+IcFFIvTN1bJ2DyWU3kR/zD9Y=; b=MQV0ozHBe1cXQqCnEZ7V3pxQTGHOvr98o0vPJTXiwxZDAVxnwiDTjnpGSqd38kF5c2CzI8 o3NFaGPdveHk/qc59UoRcZ+SqoDXo11LGt9yf5BvGKl7fKzEn53xJxQUYF7dJZRpj79Ve2 QohUC8m8NpRVcBvQDihOPTYgjOsFvyJWp0Rzpz4AI5dn6V8cdc3VSkw5cnVe4maZOXZ3ec C2BTWvPYPqpEGk3BJZdG5Pm+saImp3qFsCFcnLRcu8jiD/yRruXh4xiL44qMfKtRiNS+A8 gKmNjviIRJIKNglV4I09KTYoElCveFpgpiemH4+PpwRHY4bDqkp8C+C47D5aYA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682837901; a=rsa-sha256; cv=none; b=u63D9j5F9lZLllkHdxrwUemuufwxSsU8gRVflLvVWfH3edoW3D6NyKQxi19lpTIgFBUpzz 4zR3Gbqj4huedFTEfiYnF6nKa9q6yjQyHNN4i6Cm948bqtpJmTz3gF0Zg2OkW2YM+orbYY IHs8nLWhSbyz5bZ166MQSGXm/TGhXKEzqzwp5I0QndrtK0nPbah33kqxdnpou3Mu7PeSWt gax4SpyIlTr158JCJ5z9j3yDAHGoMvQZT4Du2/1HdR4ZJgmKHJgdJdWJSfv1UJWeMVyak5 A1JcjTlpswmHlIM2a5f5dp1PlIm9BnnUka7/zkwDX7rqY0tVD7hAkZt6ANktoQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q8HHK3FqPz1Crk; Sun, 30 Apr 2023 06:58:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33U6wLoE072065; Sun, 30 Apr 2023 06:58:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33U6wLa4072064; Sun, 30 Apr 2023 06:58:21 GMT (envelope-from git) Date: Sun, 30 Apr 2023 06:58:21 GMT Message-Id: <202304300658.33U6wLa4072064@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: ee5121192a77 - stable/13 - libc: Add missing object size check to qsort_s(3) List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: ee5121192a77cb5a713915890d6a6a2cfeeaf1a9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=ee5121192a77cb5a713915890d6a6a2cfeeaf1a9 commit ee5121192a77cb5a713915890d6a6a2cfeeaf1a9 Author: Hans Petter Selasky AuthorDate: 2023-04-19 10:22:11 +0000 Commit: Hans Petter Selasky CommitDate: 2023-04-30 06:56:20 +0000 libc: Add missing object size check to qsort_s(3) When sorting, both the C11 standard (ISO/IEC 9899:2011, K.3.6.3.2) and the ISO/IEC JTC1 SC22 WG14 N1172 standard, does not define objects of zero size as undefined behaviour. However Microsoft's cpp-docs does. Add proper checks for this. Found while working on bsort(3). Reviewed by: kib@ and emaste@ Sponsored by: NVIDIA Networking Differential Revision: https://reviews.freebsd.org/D39687 (cherry picked from commit 27bb0d337c0d82a1a4f310315840236eb239963c) --- lib/libc/stdlib/qsort.3 | 10 +++++++--- lib/libc/stdlib/qsort.c | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/libc/stdlib/qsort.3 b/lib/libc/stdlib/qsort.3 index 606185f9baee..dc14a4981fb7 100644 --- a/lib/libc/stdlib/qsort.3 +++ b/lib/libc/stdlib/qsort.3 @@ -32,7 +32,7 @@ .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd January 20, 2020 +.Dd April 19, 2023 .Dt QSORT 3 .Os .Sh NAME @@ -260,7 +260,7 @@ The order of arguments to .Fa compar is different .It -if +If .Fa nmemb or .Fa size @@ -270,7 +270,11 @@ or .Fa nmemb is not zero and .Fa compar -is NULL, then the runtime-constraint handler is called, and +is +.Dv NULL +or +.Fa size +is zero, then the runtime-constraint handler is called, and .Fn qsort_s returns an error. Note that the handler is called before diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index 410118c5cd70..98f7d02eb099 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -231,6 +231,10 @@ qsort_s(void *a, rsize_t n, rsize_t es, cmp_t *cmp, void *thunk) __throw_constraint_handler_s("qsort_s : cmp == NULL", EINVAL); return (EINVAL); + } else if (es <= 0) { + __throw_constraint_handler_s("qsort_s : es <= 0", + EINVAL); + return (EINVAL); } }