Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
spapr: Fix undefined behaviour in spapr_tce_reset()
Browse files Browse the repository at this point in the history
When a TCE table (sPAPR IOMMU context) is in disabled state (which is true
by default for the 64-bit window), it has tcet->nb_table == 0 and
tcet->table == NULL.  However, on system reset, spapr_tce_reset() executes,
which unconditionally calls
        memset(tcet->table, 0, table_size);

We get away with this in practice, because it's a zero length memset(),
but memset() on a NULL pointer is undefined behaviour, so we should not
call it in this case.

Reported-by: Peter Maydell <[email protected]>
Signed-off-by: David Gibson <[email protected]>
  • Loading branch information
dgibson committed Aug 8, 2016
1 parent 16275ed commit 57c0eb1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion hw/ppc/spapr_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ static void spapr_tce_reset(DeviceState *dev)
sPAPRTCETable *tcet = SPAPR_TCE_TABLE(dev);
size_t table_size = tcet->nb_table * sizeof(uint64_t);

memset(tcet->table, 0, table_size);
if (tcet->nb_table) {
memset(tcet->table, 0, table_size);
}
}

static target_ulong put_tce_emu(sPAPRTCETable *tcet, target_ulong ioba,
Expand Down

0 comments on commit 57c0eb1

Please sign in to comment.