From nobody Tue Jan 11 20:08:23 2022 X-Original-To: freebsd-current@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 9357B194971C for ; Tue, 11 Jan 2022 20:08:35 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic317-20.consmr.mail.gq1.yahoo.com (sonic317-20.consmr.mail.gq1.yahoo.com [98.137.66.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4JYMFt4YTxz4Tf8 for ; Tue, 11 Jan 2022 20:08:34 +0000 (UTC) (envelope-from marklmi@yahoo.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1641931706; bh=iefCQIlVpXR3sBVKYHhZgAgwF1Knmp5a77XFEUnKr0M=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From:Subject:Reply-To; b=dr0VK0g2BFfZ9bP3KikMONF2nghOU0tczjWQkyKnp1ex9thFmS4I5hbVBQNTCg4CW20J//4QY9nORhT9ad8mdXlIrBPm0M1BmpEfGUgyp8skOYTG8Ylunef+iHg33L+KvJ1TDRbB7mYLglF422DgEd7TnyFR2VS/TC1CV6kEVIMWSTLJaXTOhOb0eEWgYc74VeiC7B4z0nGo8VFpVUG6qSASYjQtdKIgIXWwrqBr20n2xKCIM5GEjdvEXAQKxcYK9UW/1f4ceIvArt8p/hrRnahxvY5k1WT11pGMwbV/+gViZ80LiV6EM4ljucT6s9Zn4wZ04Px5IDesjo80MRjqkw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1641931706; bh=FF1vnFaECHWtB3HrI7W2X9iestSXo3fIHD8H0IM5C+l=; h=X-Sonic-MF:Subject:From:Date:To:From:Subject; b=WM914OFrH3RcXIXGLwZ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dyAedgnQkEWv_Zfwt12OdEKDjgxmmF cOywgnoW8mQ2i3sQ6dTXSlsGl6uNnDWZXD0b..wEAtrrkAdnq4_nwIDU0M5LEU9Sx2gJ2lmhpi9z zqxMsijzgR2ASr9tRnLeNUcVGZV1t6G9C1aZLpmz0VmJpUu7912LTvqyfIthRmLFO8kqTOKXR0fV gc5LEqecJPfdypBhixx_AJFO0P4wau4X7Wj03to3bThlWfwrWNcxfeZrcinYknmclZldSywA2k86 cH_JRgdOwDM5IBJm3zPLfZLUJevIdxyKTPWJ545iyRzzB0AdGKKTzWDzOD9K0ainMgS5jNXnl1Hj .H1kmkA6Y2YiRMqxjO3k0E.7Adsgq4RjQCbjDx13yzeea3TuF97FCJk9_YbtV4a5JMFJb0_lsYEO .vWy7.mz_Qxt8vCng7iNn4cLZw4Vu.tKxBmjy1wp9LiJPiIBYozoIBM9AVW_ziWoytErj.bmQ5V6 eE_o_aUKfn497IGdgHSKO8Po159.4XDIn.ARPxw-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.gq1.yahoo.com with HTTP; Tue, 11 Jan 2022 20:08:26 +0000 Received: by kubenode545.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID df06ee0d4ae9d73e04b5f50238e4455c; Tue, 11 Jan 2022 20:08:23 +0000 (UTC) Content-Type: text/plain; charset=us-ascii List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: UBSAN report for main [so: 14] /usr/bin/whatis: non-zero (48) and zero offsets from null pointer in qsort.c From: Mark Millard In-Reply-To: <35333abc-9d4a-4b78-586d-1e869df4f9d4@FreeBSD.org> Date: Tue, 11 Jan 2022 12:08:23 -0800 Cc: bugs@openbsd.org, freebsd-current , Baptiste Daroussin Content-Transfer-Encoding: quoted-printable Message-Id: References: <35333abc-9d4a-4b78-586d-1e869df4f9d4@FreeBSD.org> To: Stefan Esser X-Mailer: Apple Mail (2.3654.120.0.1.13) X-Rspamd-Queue-Id: 4JYMFt4YTxz4Tf8 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On 2022-Jan-11, at 05:19, Stefan Esser wrote: > Am 11.01.22 um 08:40 schrieb Mark Millard: >> # whatis dog >> /usr/main-src/lib/libc/stdlib/qsort.c:114:23: runtime error: applying = non-zero offset 48 to null pointer >> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior = /usr/main-src/lib/libc/stdlib/qsort.c:114:23 in=20 >> /usr/main-src/lib/libc/stdlib/qsort.c:114:44: runtime error: applying = zero offset to null pointer >> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior = /usr/main-src/lib/libc/stdlib/qsort.c:114:44 in=20 >> whatis: nothing appropriate >>=20 >> This seems to be only for the not-found case. >>=20 >> =3D=3D=3D >> Mark Millard >> marklmi at yahoo.com >=20 > The undefined behavior is caused by insufficient checking of = parameters > in mansearch.c. >=20 > As part of the initializations performed at the start of mansearch(), > the variables cur and *res are initialized to 0 resp. NULL: >=20 > cur =3D maxres =3D 0;=09 > if (res !=3D NULL) > *res =3D NULL; >=20 > If no match is found, these values are unchanged at line 223, where = res > is checked to be non-NULL, but then *res is passed to qsort() and that > is still NULL. >=20 > Suggested fix (also attached to avoid white-space issues): >=20 > --- usr.bin/mandoc/mansearch.c > +++ usr.bin/mandoc/mansearch.c > @@ -220,7 +220,7 @@ > if (cur && search->firstmatch) > break; > } > - if (res !=3D NULL) > + if (res !=3D NULL && *res !=3D NULL) > qsort(*res, cur, sizeof(struct manpage), = manpage_compare); > if (chdir_status && getcwd_status && chdir(buf) =3D=3D -1) > warn("%s", buf); >=20 > (File name as in OpenBSD, it is contrib/mandoc/mansearch.c in = FreeBSD.) Cool. Thanks. (But I'm not a committer so someone else will have to deal with doing an update to the file in git --and likely MFC'ing it.) =3D=3D=3D Mark Millard marklmi at yahoo.com