ID: 3600908 - 'lib/ipmi_dcmi.c' - crash in ipmi_print_sensor_info(), NULL ref

Commit fixes crash in ipmi_print_sensor_info() in 'lib/ipmi_dcmi.c' due to NULL
reference. 'rec' is correctly checked whether NULL or not, but it's used
immediately despite of the outcome of the NULL test.
Also, ipmi_sdr_print_rawentry() is used instead of specific print function.
This commit is contained in:
Zdenek Styblik 2013-01-17 06:54:07 +00:00
parent 091ba2ea58
commit 76ed820e03

View File

@ -1974,39 +1974,37 @@ static int ipmi_print_sensor_info(struct ipmi_intf *intf, uint16_t rec_id)
struct sdr_get_rs *header; struct sdr_get_rs *header;
struct ipmi_sdr_iterator *itr; struct ipmi_sdr_iterator *itr;
int rc = 0; int rc = 0;
int r = 0;
uint8_t *rec = NULL; uint8_t *rec = NULL;
itr = ipmi_sdr_start(intf, 0); itr = ipmi_sdr_start(intf, 0);
if (itr == NULL) { if (itr == NULL) {
lprintf(LOG_ERR, "Unable to open SDR for reading"); lprintf(LOG_ERR, "Unable to open SDR for reading");
return -1; return (-1);
} }
while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) { while ((header = ipmi_sdr_get_next_header(intf, itr)) != NULL) {
if(header->id == rec_id) if (header->id == rec_id)
break; break;
} }
if(header != NULL) { if (header == NULL) {
/* yes, we found the SDR for this record ID, now get full record */ lprintf(LOG_DEBUG, "header == NULL");
rec = ipmi_sdr_get_record(intf, header, itr); ipmi_sdr_end(intf, itr);
if (rec == NULL) { return (-1);
lprintf(LOG_DEBUG, "rec == NULL"); }
rc = -1; /* yes, we found the SDR for this record ID, now get full record */
} rec = ipmi_sdr_get_record(intf, header, itr);
if (rec == NULL) {
if((header->type == SDR_RECORD_TYPE_FULL_SENSOR) || lprintf(LOG_DEBUG, "rec == NULL");
(header->type == SDR_RECORD_TYPE_COMPACT_SENSOR)) { ipmi_sdr_end(intf, itr);
r = ipmi_sensor_print_fc(intf, return (-1);
(struct sdr_record_common_sensor *)rec, header->type); }
} if ((header->type == SDR_RECORD_TYPE_FULL_SENSOR) ||
else (header->type == SDR_RECORD_TYPE_COMPACT_SENSOR)) {
rc = -1; rc = ipmi_sdr_print_rawentry(intf, header->type, rec, header->length);
} else {
rc = (-1);
} }
else {
rc = -1; /* record id not found */
}
free(rec); free(rec);
ipmi_sdr_end(intf, itr); ipmi_sdr_end(intf, itr);