From 6d9c540f6b2dc16486abc557516f21f8313d6d72 Mon Sep 17 00:00:00 2001 From: Alexander Amelkin Date: Tue, 3 Apr 2018 19:46:35 +0300 Subject: [PATCH] ID:508 - Fix segfaults in dcmi command handlers Some command lists were not terminated properly. This commit fixes that. --- lib/ipmi_dcmi.c | 76 ++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/lib/ipmi_dcmi.c b/lib/ipmi_dcmi.c index 2cfe48f..a76b1f2 100755 --- a/lib/ipmi_dcmi.c +++ b/lib/ipmi_dcmi.c @@ -74,6 +74,8 @@ static int ipmi_print_sensor_info(struct ipmi_intf *intf, uint16_t rec_id); * to change a lot of the code in the main(). * ******************************************************************************/ +#define DCMI_CMD_END { 0xFF, NULL, NULL } + /* Main set of DCMI commands */ const struct dcmi_cmd dcmi_cmd_vals[] = { { 0x00, "discover", " Used to discover supported DCMI capabilities" }, @@ -88,7 +90,7 @@ const struct dcmi_cmd dcmi_cmd_vals[] = { { 0x09, "get_conf_param", " Get DCMI Config Parameters" }, { 0x0A, "set_conf_param", " Set DCMI Config Parameters" }, { 0x0B, "oob_discover", " Ping/Pong Message for DCMI Discovery" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* get capabilites */ @@ -98,7 +100,7 @@ const struct dcmi_cmd dcmi_capable_vals[] = { "temperature attributes" }, { 0x03, "optional_attributes", " Lists power capabilities" }, { 0x04, "managebility access", " Lists OOB channel information" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* platform capabilities @@ -110,13 +112,13 @@ const struct dcmi_cmd dcmi_mandatory_platform_capabilities[] = { { 0x02, "SEL logging available", "" }, { 0x03, "Chassis power available", "" }, { 0x04, "Temperature monitor available", "" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* optional capabilities */ const struct dcmi_cmd dcmi_optional_platform_capabilities[] = { { 0x01, "Power management available", "" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* access capabilties */ @@ -127,7 +129,7 @@ const struct dcmi_cmd dcmi_management_access_capabilities[] = { { 0x04, "Out-of-band primary LAN channel available", "" }, { 0x05, "SOL enabled", "" }, { 0x06, "VLAN capable", "" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* identification capabilities */ @@ -135,7 +137,7 @@ const struct dcmi_cmd dcmi_id_capabilities_vals[] = { { 0x01, "GUID", "" }, { 0x02, "DHCP hostname", "" }, { 0x03, "Asset tag", "" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* Configuration parameters*/ @@ -145,7 +147,7 @@ const struct dcmi_cmd dcmi_conf_param_vals[] = { { 0x03, "init", "\t\tInitial timeout interval" }, { 0x04, "timeout", "\t\tServer contact timeout interval" }, { 0x05, "retry", "\t\tServer contact retry interval" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; @@ -154,7 +156,7 @@ const struct dcmi_cmd dcmi_temp_monitoring_vals[] = { { 0x01, "inlet", " Inlet air temperature sensors" }, { 0x02, "cpu", " CPU temperature sensors" }, { 0x03, "baseboard", "Baseboard temperature sensors" }, - { 0xff, NULL, NULL } + { 0xff, NULL, NULL } }; /* These are not comands. These are the DCMI temp sensors and their numbers @@ -165,7 +167,7 @@ const struct dcmi_cmd dcmi_discvry_snsr_vals[] = { { 0x40, "Inlet", " Inlet air temperature sensors" }, { 0x41, "CPU", " CPU temperature sensors" }, { 0x42, "Baseboard", "Baseboard temperature sensors" }, - { 0xff, NULL, NULL } + { 0xff, NULL, NULL } }; /* Temperature Readings */ @@ -173,7 +175,7 @@ const struct dcmi_cmd dcmi_temp_read_vals[] = { { 0x40, "Inlet", "Inlet air temperature(40h) " }, { 0x41, "CPU", "CPU temperature sensors(41h) " }, { 0x42, "Baseboard", "Baseboard temperature sensors(42h) " }, - { 0xff, NULL, NULL } + { 0xff, NULL, NULL } }; /* power management/control commands */ @@ -183,7 +185,7 @@ const struct dcmi_cmd dcmi_pwrmgmt_vals[] = { { 0x02, "set_limit", " Set a power limit option" }, { 0x03, "activate", " Activate the set power limit" }, { 0x04, "deactivate", "Deactivate the set power limit" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* set power limit commands */ @@ -192,7 +194,7 @@ const struct dcmi_cmd dcmi_pwrmgmt_set_usage_vals[] = { { 0x01, "limit", " " }, { 0x02, "correction", "" }, { 0x03, "sample", " " }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* power management/get action commands */ @@ -217,7 +219,7 @@ const struct dcmi_cmd dcmi_pwrmgmt_get_action_vals[] = { { 0x10, "OEM reserved (10h)", ""}, { 0x11, "Log Event to SEL", ""}, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* power management/set action commands */ @@ -242,21 +244,21 @@ const struct dcmi_cmd dcmi_pwrmgmt_action_vals[] = { { 0x0f, "oem_0f", "OEM reserved (0fh)"}, { 0x10, "oem_10", "OEM reserved (10h)"}, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* thermal policy action commands */ const struct dcmi_cmd dcmi_thermalpolicy_vals[] = { { 0x00, "get", "Get thermal policy" }, { 0x01, "set", "Set thermal policy" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* thermal policy action commands */ const struct dcmi_cmd dcmi_confparameters_vals[] = { { 0x00, "get", "Get configuration parameters" }, { 0x01, "set", "Set configuration parameters" }, - { 0xFF, NULL, NULL } + DCMI_CMD_END }; /* entityIDs used in thermap policy */ @@ -268,7 +270,7 @@ const struct dcmi_cmd dcmi_thermalpolicy_set_parameters_vals[] = { { 0x01, "sel", " Log event to SEL" }, { 0x00, "nosel", " No 'Log event to SEL' action" }, { 0x00, "disabled", " Disabled" }, - { 0x00, NULL, NULL } + { 0x00, NULL, NULL } }; @@ -325,20 +327,20 @@ const struct dcmi_cmd nm_cmd_vals[] = { { 0x07, "reset", "Reset Statistics" }, { 0x08, "alert", "Set/Get/Clear Alert destination" }, { 0x09, "threshold", "Set/Get Alert Thresholds" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_ctl_cmds[] = { { 0x01, "enable", " " }, { 0x00, "disable", ""}, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_ctl_domain[] = { { 0x00, "global", "" }, { 0x02, "per_domain", " (default is platform)" }, { 0x04, "per_policy", "<0-7>" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; /* Node Manager Domain codes */ @@ -348,7 +350,7 @@ const struct dcmi_cmd nm_domain_vals[] = { { 0x02, "Memory", "" }, { 0x03, "protection", "" }, { 0x04, "I/O", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_version_vals[] = { @@ -357,7 +359,7 @@ const struct dcmi_cmd nm_version_vals[] = { { 0x03, "2.0", "" }, { 0x04, "2.5", "" }, { 0x05, "3.0", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_capability_opts[] = { @@ -366,7 +368,7 @@ const struct dcmi_cmd nm_capability_opts[] = { { 0x03, "missing", "Missing Power reading trigger" }, { 0x04, "reset", "Time after Host reset trigger" }, { 0x05, "boot", "Boot time policy" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_policy_type_vals[] = { @@ -375,13 +377,13 @@ const struct dcmi_cmd nm_policy_type_vals[] = { { 0x02, "Missing Power reading trigger", "" }, { 0x03, "Time after Host reset trigger", "" }, { 0x04, "number of cores to disable at boot time", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_stats_opts[] = { { 0x01, "domain", " (default is platform)" }, { 0x02, "policy_id", "<0-7>" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_stats_mode[] = { @@ -395,7 +397,7 @@ const struct dcmi_cmd nm_stats_mode[] = { { 0x1D, "cpu_throttling", "CPU throttling" }, { 0x1E, "mem_throttling", "memory throttling" }, { 0x1F, "comm_fail", "host communication failures" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_policy_action[] = { @@ -403,7 +405,7 @@ const struct dcmi_cmd nm_policy_action[] = { { 0x04, "add", "nm policy add policy_id <0-7> [domain ] correction auto|soft|hard power |inlet trig_lim stats enable|disable" }, { 0x05, "remove", "nm policy remove policy_id <0-7> [domain ]" }, { 0x06, "limiting", "nm policy limiting [domain ]" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_policy_options[] = { { 0x01, "enable", "" }, @@ -417,7 +419,7 @@ const struct dcmi_cmd nm_policy_options[] = { { 0x0B, "policy_id", "policy number" }, { 0x0C, "volatile", "save policy in volatiel memory" }, { 0x0D, "cores_off", "at boot time, disable N cores" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; /* if "trigger" command used from nm_policy_options */ @@ -426,7 +428,7 @@ const struct dcmi_cmd nm_trigger[] = { { 0x01, "temp", "" }, { 0x02, "reset", "" }, { 0x03, "boot", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; /* if "correction" used from nm_policy_options */ @@ -434,7 +436,7 @@ const struct dcmi_cmd nm_correction[] = { { 0x00, "auto", "" }, { 0x01, "soft", "" }, { 0x02, "hard", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; /* returned codes from get policy */ @@ -442,7 +444,7 @@ const struct dcmi_cmd nm_correction_vals[] = { { 0x00, "no T-state use", "" }, { 0x01, "no T-state use", "" }, { 0x02, "use T-states", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; /* if "exception" used from nm_policy_options */ @@ -450,7 +452,7 @@ const struct dcmi_cmd nm_exception[] = { { 0x00, "none", "" }, { 0x01, "alert", "" }, { 0x02, "shutdown", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_reset_mode[] = { @@ -461,42 +463,46 @@ const struct dcmi_cmd nm_reset_mode[] = { { 0x1D, "throttling", "" }, { 0x1E, "memory", "", }, { 0x1F, "comm", "" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_power_range[] = { { 0x01, "domain", "domain (default is platform)" }, { 0x02, "min", " min " }, { 0x03, "max", "max " }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_alert_opts[] = { { 0x01, "set", "nm alert set chan dest string " }, { 0x02, "get", "nm alert get" }, { 0x03, "clear", "nm alert clear dest " }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_set_alert_param[] = { { 0x01, "chan", "chan " }, { 0x02, "dest", "dest " }, { 0x03, "string", "string " }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_thresh_cmds[] = { { 0x01, "set", "nm thresh set [domain ] policy_id thresh_array" }, { 0x02, "get", "nm thresh get [domain ] policy_id " }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_thresh_param[] = { { 0x01, "domain", " (default is platform)" }, { 0x02, "policy_id", "<0-7>" }, - { 0xFF, NULL, NULL }, + DCMI_CMD_END, }; const struct dcmi_cmd nm_suspend_cmds[] = { { 0x01, "set", "nm suspend set [domain policy_id " }, { 0x02, "get", "nm suspend get [domain policy_id " }, + DCMI_CMD_END, }; const struct valstr nm_ccode_vals[] = {