charge_manager: fix possible out of bound read access

The port id given by the kernel is never checked and out-of-bound
read accesses can be made on available_charge. Fix it.

Change-Id: I06ed3d28c30db77d8256e9af808484a7cbdc901e
Signed-off-by: Fabien Parent <fparent@baylibre.com>
Reviewed-on: https://chromium-review.googlesource.com/1046592
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
This commit is contained in:
Fabien Parent
2018-05-05 13:45:07 +02:00
committed by chrome-bot
parent 7034d8b711
commit e4b718df7a

View File

@@ -1079,6 +1079,9 @@ static int hc_pd_power_info(struct host_cmd_handler_args *args)
if (port == PD_POWER_CHARGING_PORT)
port = charge_port;
if (port >= CHARGE_PORT_COUNT)
return EC_RES_INVALID_PARAM;
charge_manager_fill_power_info(port, r);
args->response_size = sizeof(*r);