From nobody Mon Feb 28 22:41:11 2022 X-Original-To: dev-commits-src-all@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 43DA819E2C51; Mon, 28 Feb 2022 22:41:13 +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 4K6wMr1wmWz3LgQ; Mon, 28 Feb 2022 22:41:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646088072; 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=1pjheDY3hWEJQKgiuRchQTjhwDX5SwGDMZl1WC5FxHI=; b=uF3L3S2FTnx405V7X0NBByA28KQe8gzNMwwjoUrHMMcs9M7mfct9EPU8Sen0fVl281w+gG TQotkzqOiFeOhbGDZOcNYST35TOV6WfNK1gxH86t78/U/TEDkLQXhA3LyzlcYc2c0OuN7R oIFCPfIhFU2YILBoAOF89dPxRJtqa+bwHmPm0GgHznIAdov5/h1XvQ5PTnSIkJZzyq6Nvr rvswTqpJcN/r9UDWWVYYwjUFME3RIqLxT93NvSW7+mQU1kr3//BHbTL0EbM0GhcsEwKt07 eaCp9inMl5SOerNqhqsMKff14p6jCzyxqT5AWewhDnrIRL/TIlNmo9oOGI9j9Q== 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 F333B23879; Mon, 28 Feb 2022 22:41:11 +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 21SMfB40063001; Mon, 28 Feb 2022 22:41:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21SMfBSP063000; Mon, 28 Feb 2022 22:41:11 GMT (envelope-from git) Date: Mon, 28 Feb 2022 22:41:11 GMT Message-Id: <202202282241.21SMfBSP063000@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jessica Clarke Subject: git: 89f5bc467c79 - main - dtc: Sync with upstream version e9a77451cdd8 List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jrtc27 X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 89f5bc467c793a6023bfac8db519a8d74f21a8d0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646088072; 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=1pjheDY3hWEJQKgiuRchQTjhwDX5SwGDMZl1WC5FxHI=; b=n7+9CAbKfc8THnKdMPft+6RLzxOCmJRbpxlW8OK4d2RcvlWdzaJBEgX1qoLf5RDRtQVGcN m0VhX1I7oTXIGEzF8Vk7lk0n6enf6y3HH+S+teO4puNNZFHiQs0IsuGttQkaX/u/Xhd61d C+/gxfuj9TMElPdZ9RWJ1+GIuvCYpTqiw2P4UCApH6tGUccYAv7N1Ygew23hKl0U8rD980 Op06JEHRvAlEny0LC70XABSNJlQEsEg/DMce+RAc4NhG8EuswC3pniLEgylfCr2EObDpsY TDfaB7Y6XaOR3CCnNXaFvBaKahKuMAgpbDnDNLfCWRCNq7QTzHTO1SGfRe3UIg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646088072; a=rsa-sha256; cv=none; b=VmL0L26WFb1sFwogXiocTPbkEF6c8iH9O9lBhFtYdugJQIN7NFHvkWBIkEIfiqM8PvP2nk hOgPxp7AukCw4Zyj2O3exSKULlhCIQghMk+3a0PYDBH1MSjWaVhvOM3H0abS7SEwnYOzCm D0GmUHQdd58x2uzTvid13PezsgHv2InSgqTmYcerNkoNnjRvuzsJAQVdAq74b3KfhoDeUg RuY30FjiohEIaWpCWQWWA3SNqKvRkxClse3XFZfT2V/J79RdBTkZVCnwvV5+u3SqPJA7S/ UGiYkvriODCwg5jAh4hQGf3LXm7DdtQswFAhpuvsKyzvxUBrbdbunsSCfhnq9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jrtc27: URL: https://cgit.FreeBSD.org/src/commit/?id=89f5bc467c793a6023bfac8db519a8d74f21a8d0 commit 89f5bc467c793a6023bfac8db519a8d74f21a8d0 Author: Jessica Clarke AuthorDate: 2022-02-28 22:37:47 +0000 Commit: Jessica Clarke CommitDate: 2022-02-28 22:37:47 +0000 dtc: Sync with upstream version e9a77451cdd8 1c231509cf88 ("Validate integers fit in cells") is the only change missing from our copy. Reviewed by: manu, imp Differential Revision: https://reviews.freebsd.org/D34368 --- usr.bin/dtc/fdt.cc | 18 ++++++++++++++++++ usr.bin/dtc/input_buffer.cc | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/usr.bin/dtc/fdt.cc b/usr.bin/dtc/fdt.cc index 3c7b2a8bd9ab..bdfd495a02d2 100644 --- a/usr.bin/dtc/fdt.cc +++ b/usr.bin/dtc/fdt.cc @@ -335,10 +335,28 @@ property::parse_cells(text_input_buffer &input, int cell_size) unsigned long long val; if (!input.consume_integer_expression(val)) { + // FIXME: Distinguish invalid syntax from a + // number that cannot be represented in an + // unsigned long long. input.parse_error("Expected numbers in array of cells"); valid = false; return; } + // FIXME: No sign information available, so cannot + // distinguish small negative values from large + // positive ones, and thus we have to conservatively + // permit anything that looks like a sign-extended + // negative integer. + if (cell_size < 64 && val >= (1ull << cell_size) && + (val | ((1ull << (cell_size - 1)) - 1)) != + std::numeric_limits::max()) + { + std::string msg = "Value does not fit in a " + + std::to_string(cell_size) + "-bit cell"; + input.parse_error(msg.c_str()); + valid = false; + return; + } switch (cell_size) { case 8: diff --git a/usr.bin/dtc/input_buffer.cc b/usr.bin/dtc/input_buffer.cc index 1f4775c8b78c..01ab483353c0 100644 --- a/usr.bin/dtc/input_buffer.cc +++ b/usr.bin/dtc/input_buffer.cc @@ -349,8 +349,11 @@ input_buffer::consume_integer(unsigned long long &outInt) return false; } char *end= const_cast(&buffer[size]); + errno = 0; outInt = strtoull(&buffer[cursor], &end, 0); - if (end == &buffer[cursor]) + if (end == &buffer[cursor] || + (outInt == std::numeric_limits::max() && + errno == ERANGE)) { return false; }