]> git.ipfire.org Git - thirdparty/grub.git/commit
commands/menuentry: Fix quoting in setparams_prefix()
authorDaniel Axtens <dja@axtens.net>
Fri, 22 Jan 2021 06:10:48 +0000 (17:10 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:17 +0000 (15:54 +0100)
commit2f533a89a8dfcacbf2c9dbc77d910f111f24bf33
tree656fd8d13ad0c7c995075af5fb54dea5289b6948
parent0a05f88e2bb33ed2a0cfd93f481f471efb7791aa
commands/menuentry: Fix quoting in setparams_prefix()

Commit 9acdcbf32542 (use single quotes in menuentry setparams command)
says that expressing a quoted single quote will require 3 characters. It
actually requires (and always did require!) 4 characters:

  str: a'b => a'\''b
  len:  3  => 6 (2 for the letters + 4 for the quote)

This leads to not allocating enough memory and thus out of bounds writes
that have been observed to cause heap corruption.

Allocate 4 bytes for each single quote.

Commit 22e7dbb2bb81 (Fix quoting in legacy parser.) does the same
quoting, but it adds 3 as extra overhead on top of the single byte that
the quote already needs. So it's correct.

Fixes: 9acdcbf32542 (use single quotes in menuentry setparams command)
Fixes: CVE-2021-20233
Reported-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/commands/menuentry.c