modem_info_get_current_band in modem_info.c is using wrong value type

modem_info_get_current_band expects an uint8 pointer to store the band into, but scans for an unsigned int (probably above 8 bit) in nrf_modem_at_scanf. This leads to memory corruption when used with, as the function definition may suggest, an uint8. The workaround is to use it with an unsigned integer. The bug is present in SDK 2.6.1. I did not check the other SDK versions.

int modem_info_get_current_band(uint8_t *val)
{
	if (val == NULL) {
		return -EINVAL;
	}

	int ret = nrf_modem_at_scanf("AT%XCBAND", "%%XCBAND: %u", val);

	if (ret != 1) {
		LOG_ERR("Could not get band, error: %d", ret);
		return map_nrf_modem_at_scanf_error(ret);
	}

	if (*val == BAND_UNAVAILABLE) {
		LOG_WRN("No valid band");
		return -ENOENT;
	}

	return 0;
}

Parents Reply Children
Related