snmp: avoid NULL pointer dereference, fix return values

This commit is contained in:
Simon Goldschmidt 2018-10-24 20:39:08 +02:00
parent e678219bdf
commit 398333da9a
2 changed files with 18 additions and 6 deletions

View File

@ -193,7 +193,7 @@ snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, st
static s16_t
snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value)
{
s16_t result = SNMP_ERR_NOSUCHINSTANCE;
s16_t result = -1;
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
@ -206,7 +206,7 @@ snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value)
static snmp_err_t
snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value)
{
snmp_err_t result = SNMP_ERR_NOSUCHINSTANCE;
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
@ -219,7 +219,7 @@ snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len,
static snmp_err_t
snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value)
{
snmp_err_t result = SNMP_ERR_NOSUCHINSTANCE;
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;

View File

@ -55,7 +55,11 @@ threadsync_get_value_synced(void *ctx)
{
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
if (call_data->proxy_instance.get_value != NULL) {
call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
} else {
call_data->retval.s16 = -1;
}
sys_sem_signal(&call_data->threadsync_node->instance->sem);
}
@ -76,7 +80,11 @@ threadsync_set_test_synced(void *ctx)
{
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
if (call_data->proxy_instance.set_test != NULL) {
call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
} else {
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
}
sys_sem_signal(&call_data->threadsync_node->instance->sem);
}
@ -98,7 +106,11 @@ threadsync_set_value_synced(void *ctx)
{
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
if (call_data->proxy_instance.set_value != NULL) {
call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
} else {
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
}
sys_sem_signal(&call_data->threadsync_node->instance->sem);
}