1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-27 23:22:37 +02:00

programmer.h: Convert anon union to anon struct

Convert the anon union of registered masters in the mst
field of the flashctx to a anon struct. If we are going
to dereference a pointer there in an undefined way we
should crash and not plow ahead with invalid memory.

The user of the registered_masters type is therefore
responsible for querying the buses_supported field before
attempting to dereference a ptr field in the anon struct.

BUG=b:175849641
TEST=`flashrom -p internal --flash-name`

Change-Id: I576967a8599b923c902e39f177f39146291cc242
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/50246
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-by: Daniel Campello <campello@chromium.org>
Reviewed-by: Sam McNally <sammc@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Edward O'Callaghan 2021-02-03 11:19:41 +11:00 committed by Edward O'Callaghan
parent 1a9441f748
commit 4eef651ff5
4 changed files with 5 additions and 4 deletions

View File

@ -48,7 +48,7 @@ int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int bl
int register_opaque_master(const struct opaque_master *mst) int register_opaque_master(const struct opaque_master *mst)
{ {
struct registered_master rmst; struct registered_master rmst = {0};
if (!mst->probe || !mst->read || !mst->write || !mst->erase) { if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
msg_perr("%s called with incomplete master definition. " msg_perr("%s called with incomplete master definition. "

View File

@ -83,7 +83,8 @@ void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf,
int register_par_master(const struct par_master *mst, int register_par_master(const struct par_master *mst,
const enum chipbustype buses) const enum chipbustype buses)
{ {
struct registered_master rmst; struct registered_master rmst = {0};
if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel || if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel ||
!mst->chip_writen || !mst->chip_readb || !mst->chip_readw || !mst->chip_writen || !mst->chip_readb || !mst->chip_readw ||
!mst->chip_readl || !mst->chip_readn) { !mst->chip_readl || !mst->chip_readn) {

View File

@ -749,7 +749,7 @@ struct par_master {
int register_par_master(const struct par_master *mst, const enum chipbustype buses); int register_par_master(const struct par_master *mst, const enum chipbustype buses);
struct registered_master { struct registered_master {
enum chipbustype buses_supported; enum chipbustype buses_supported;
union { struct {
struct par_master par; struct par_master par;
struct spi_master spi; struct spi_master spi;
struct opaque_master opaque; struct opaque_master opaque;

2
spi.c
View File

@ -133,7 +133,7 @@ int spi_aai_write(struct flashctx *flash, const uint8_t *buf, unsigned int start
int register_spi_master(const struct spi_master *mst) int register_spi_master(const struct spi_master *mst)
{ {
struct registered_master rmst; struct registered_master rmst = {0};
if (!mst->write_aai || !mst->write_256 || !mst->read || !mst->command || if (!mst->write_aai || !mst->write_256 || !mst->read || !mst->command ||
!mst->multicommand || !mst->multicommand ||