This fixes an out-of-bounds read of the riot_optional_symbols array.
Change-Id: I172ae182dd0c7dd68edaa66ac030030d9bc65401
Signed-off-by: Sebastiaan de Schaetzen <sebastiaan.de.schaetzen@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6428
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
-/* refer RIOT core/sched.c */
-static const char *const riot_symbol_list[] = {
- "sched_threads",
- "sched_num_threads",
- "sched_active_pid",
- "max_threads",
- "_tcb_name_offset",
- NULL
+struct riot_symbol {
+ const char *const name;
+ bool optional;
-/* Define which symbols are not mandatory */
-static const enum riot_symbol_values riot_optional_symbols[] = {
- RIOT_NAME_OFFSET,
+/* refer RIOT core/sched.c */
+static struct riot_symbol const riot_symbol_list[] = {
+ {"sched_threads", false},
+ {"sched_num_threads", false},
+ {"sched_active_pid", false},
+ {"max_threads", false},
+ {"_tcb_name_offset", true},
+ {NULL, false}
};
const struct rtos_type riot_rtos = {
};
const struct rtos_type riot_rtos = {
if (rtos->symbols[RIOT_THREADS_BASE].address == 0) {
LOG_ERROR("Can't find symbol `%s`",
if (rtos->symbols[RIOT_THREADS_BASE].address == 0) {
LOG_ERROR("Can't find symbol `%s`",
- riot_symbol_list[RIOT_THREADS_BASE]);
+ riot_symbol_list[RIOT_THREADS_BASE].name);
(uint16_t *)&active_pid);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
(uint16_t *)&active_pid);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
- riot_symbol_list[RIOT_ACTIVE_PID]);
+ riot_symbol_list[RIOT_ACTIVE_PID].name);
return retval;
}
rtos->current_thread = active_pid;
return retval;
}
rtos->current_thread = active_pid;
(uint16_t *)&thread_count);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
(uint16_t *)&thread_count);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
- riot_symbol_list[RIOT_NUM_THREADS]);
+ riot_symbol_list[RIOT_NUM_THREADS].name);
return retval;
}
rtos->thread_count = thread_count;
return retval;
}
rtos->thread_count = thread_count;
&max_threads);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
&max_threads);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
- riot_symbol_list[RIOT_MAX_THREADS]);
+ riot_symbol_list[RIOT_MAX_THREADS].name);
&name_offset);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
&name_offset);
if (retval != ERROR_OK) {
LOG_ERROR("Can't read symbol `%s`",
- riot_symbol_list[RIOT_NAME_OFFSET]);
+ riot_symbol_list[RIOT_NAME_OFFSET].name);
threads_base + (i * 4),
&tcb_pointer);
if (retval != ERROR_OK) {
threads_base + (i * 4),
&tcb_pointer);
if (retval != ERROR_OK) {
- LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE]);
+ LOG_ERROR("Can't parse `%s`",
+ riot_symbol_list[RIOT_THREADS_BASE].name);
tcb_pointer + param->thread_status_offset,
&status);
if (retval != ERROR_OK) {
tcb_pointer + param->thread_status_offset,
&status);
if (retval != ERROR_OK) {
- LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE]);
+ LOG_ERROR("Can't parse `%s`",
+ riot_symbol_list[RIOT_THREADS_BASE].name);
&name_pointer);
if (retval != ERROR_OK) {
LOG_ERROR("Can't parse `%s`",
&name_pointer);
if (retval != ERROR_OK) {
LOG_ERROR("Can't parse `%s`",
- riot_symbol_list[RIOT_THREADS_BASE]);
+ riot_symbol_list[RIOT_THREADS_BASE].name);
(uint8_t *)&buffer);
if (retval != ERROR_OK) {
LOG_ERROR("Can't parse `%s`",
(uint8_t *)&buffer);
if (retval != ERROR_OK) {
LOG_ERROR("Can't parse `%s`",
- riot_symbol_list[RIOT_THREADS_BASE]);
+ riot_symbol_list[RIOT_THREADS_BASE].name);
threads_base + (thread_id * 4),
&tcb_pointer);
if (retval != ERROR_OK) {
threads_base + (thread_id * 4),
&tcb_pointer);
if (retval != ERROR_OK) {
- LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE]);
+ LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE].name);
tcb_pointer + param->thread_sp_offset,
&stackptr);
if (retval != ERROR_OK) {
tcb_pointer + param->thread_sp_offset,
&stackptr);
if (retval != ERROR_OK) {
- LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE]);
+ LOG_ERROR("Can't parse `%s`", riot_symbol_list[RIOT_THREADS_BASE].name);
}
for (unsigned int i = 0; i < ARRAY_SIZE(riot_symbol_list); i++) {
}
for (unsigned int i = 0; i < ARRAY_SIZE(riot_symbol_list); i++) {
- (*symbol_list)[i].symbol_name = riot_symbol_list[i];
- (*symbol_list)[i].optional = false;
-
- /* Lookup if symbol is optional */
- for (unsigned int k = 0; k < sizeof(riot_optional_symbols); k++) {
- if (i == riot_optional_symbols[k]) {
- (*symbol_list)[i].optional = true;
- break;
- }
- }
+ (*symbol_list)[i].symbol_name = riot_symbol_list[i].name;
+ (*symbol_list)[i].optional = riot_symbol_list[i].optional;