From 90b3095093512f048d055a40ffc6b7acbf2a835a Mon Sep 17 00:00:00 2001 From: Richard Spiegel Date: Tue, 17 Apr 2018 10:09:17 -0700 Subject: mb/google/cyan/spd/spd.c: Fix module part number transfer With the increase of dimm->module_part_number size from 19 to 21 (commit 35b273eea3) "include/memory_info.h: Change part number field from 19 bytes to 21", this code is now advancing outside DDR3 SPD designated space. The correct size is already defined as LPDDR3_SPD_PART_LEN, use it. Also make sure to 0 terminate the string. BUG=b:77943312 TEST=Build cyan. Change-Id: Iba0ef4149acfc09b7672fce079df06bf1a01dff6 Signed-off-by: Richard Spiegel Reviewed-on: https://review.coreboot.org/25702 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth Reviewed-by: Raul Rangel Reviewed-by: Paul Menzel --- src/mainboard/google/cyan/spd/spd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/mainboard/google/cyan') diff --git a/src/mainboard/google/cyan/spd/spd.c b/src/mainboard/google/cyan/spd/spd.c index 97e14eb758..106faf4c9c 100644 --- a/src/mainboard/google/cyan/spd/spd.c +++ b/src/mainboard/google/cyan/spd/spd.c @@ -145,8 +145,9 @@ static void set_dimm_info(uint8_t *spd, struct dimm_info *dimm) } dimm->dimm_size = capmb / 8 * busw / devw * ranks; /* MiB */ dimm->mod_type = spd[3] & 0xf; - memcpy((char *)&dimm->module_part_number[0], &spd[0x80], - sizeof(dimm->module_part_number) - 1); + strncpy((char *)&dimm->module_part_number[0], (char *)&spd[0x80], + LPDDR3_SPD_PART_LEN); + dimm->module_part_number[LPDDR3_SPD_PART_LEN] = 0; dimm->mod_id = *(uint16_t *)&spd[0x94]; switch (busw) { -- cgit v1.2.3