Received: from eggs.gnu.org ([2001:4830:134:3::10]:47780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGVRP-0005Uc-OX for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGVRM-0001mL-Ij for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:39 -0500 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:56517) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGVRM-0001kb-Af for qemu-devel@nongnu.org; Tue, 05 Jan 2016 12:30:36 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Jan 2016 17:30:33 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 584F217D8042 for ; Tue, 5 Jan 2016 17:31:16 +0000 (GMT) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u05HUVQu7340494 for ; Tue, 5 Jan 2016 17:30:31 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u05HUVMa021530 for ; Tue, 5 Jan 2016 10:30:31 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Date: Tue, 5 Jan 2016 18:29:55 +0100 Message-Id: <1452015002-28493-2-git-send-email-clg@fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 1/8] ipmi: fix SDR length value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Corey Minyard Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-devel@nongnu.org, "Michael S. Tsirkin" The IPMI BMC simulator populates the SDR table with a set of initial SDRs. The length of each SDR is taken from the record itself (byte 4) which does not include the size of the header. But, the full length (header + data) is required by the sdr_add_entry() routine. Signed-off-by: Cédric Le Goater --- Maybe we could use a sdr struct/typedef to clarify the code. See patch 7: "ipmi: introduce an ipmi_bmc_init_sensor() API" hw/ipmi/ipmi_bmc_sim.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c index 0a59e539f549..559e1398d669 100644 --- a/hw/ipmi/ipmi_bmc_sim.c +++ b/hw/ipmi/ipmi_bmc_sim.c @@ -362,7 +362,7 @@ static int sdr_find_entry(IPMISdr *sdr, uint16_t recid, while (pos < sdr->next_free) { uint16_t trec = sdr->sdr[pos] | (sdr->sdr[pos + 1] << 8); - unsigned int nextpos = pos + sdr->sdr[pos + 4]; + unsigned int nextpos = pos + sdr->sdr[pos + 4] + 5; if (trec == recid) { if (nextrec) { @@ -1198,7 +1198,7 @@ static void get_sdr(IPMIBmcSim *ibs, rsp[2] = IPMI_CC_REQ_ENTRY_NOT_PRESENT; goto out; } - if (cmd[6] > (ibs->sdr.sdr[pos + 4])) { + if (cmd[6] > (ibs->sdr.sdr[pos + 4] + 5)) { rsp[2] = IPMI_CC_PARM_OUT_OF_RANGE; goto out; } @@ -1207,7 +1207,7 @@ static void get_sdr(IPMIBmcSim *ibs, IPMI_ADD_RSP_DATA((nextrec >> 8) & 0xff); if (cmd[7] == 0xff) { - cmd[7] = ibs->sdr.sdr[pos + 4] - cmd[6]; + cmd[7] = ibs->sdr.sdr[pos + 4] + 5 - cmd[6]; } if ((cmd[7] + *rsp_len) > max_rsp_len) { @@ -1709,20 +1709,20 @@ static void ipmi_sim_init(Object *obj) for (i = 0;;) { int len; if ((i + 5) > sizeof(init_sdrs)) { - error_report("Problem with recid 0x%4.4x: \n", i); + error_report("Problem with recid 0x%4.4x\n", i); return; } - len = init_sdrs[i + 4]; + len = init_sdrs[i + 4] + 5; recid = init_sdrs[i] | (init_sdrs[i + 1] << 8); if (recid == 0xffff) { break; } - if ((i + len + 5) > sizeof(init_sdrs)) { + if ((i + len) > sizeof(init_sdrs)) { error_report("Problem with recid 0x%4.4x\n", i); return; } sdr_add_entry(ibs, init_sdrs + i, len, NULL); - i += len + 5; + i += len; } ipmi_init_sensors_from_sdrs(ibs); -- 2.1.4