- memcpy(token->str, input, len);
- token->str[len] = '\0';
-
+ /* copy at most n bytes from input with offset t_off into token->str */
+ sstrncpy(token->str, input, len + 1);
const index_key_src_t source = td->index_keys[i].source;
c_avl_tree_t *const tokens = td->tokens[source];
/* Generating list filled with all data necessary to generate an OID */
const index_key_src_t source = td->index_keys[i].source;
c_avl_tree_t *const tokens = td->tokens[source];
/* Generating list filled with all data necessary to generate an OID */
int ret = parse_oid_indexes(index_oid->oid, index_oid->oid_len,
td->index_list_cont);
if (ret != SNMPERR_SUCCESS)
int ret = parse_oid_indexes(index_oid->oid, index_oid->oid_len,
td->index_list_cont);
if (ret != SNMPERR_SUCCESS)
if (tok->key != NULL) {
if (tok->key->type == ASN_INTEGER) {
snprintf(str, sizeof(str), "%ld", *tok->key->val.integer);
if (tok->key != NULL) {
if (tok->key->type == ASN_INTEGER) {
snprintf(str, sizeof(str), "%ld", *tok->key->val.integer);
- strncat(out, str, strlen(str));
- } else { /* OCTET_STR */
+ strncat(out, str, DATA_MAX_NAME_LEN - strlen(out) - 1);
+ } else /* OCTET_STR */
- table_definition_t *td, oid_t **index_oid) {
+ table_definition_t *td, oid_t *index_oid,
+ bool *free_index_oid) {
- if (c_avl_get(td->instance_index, (void *)*index_oid, (void **)&index) != 0) {
- /* Processing new instance */
- do_free_index_oid = false;
+ if (c_avl_get(td->instance_index, (void *)index_oid, (void **)&index) != 0) {
+ /* We'll keep index_oid stored in AVL tree */
+ *free_index_oid = false;
/* need to generate index for the table */
if (td->index_oid.oid_len) {
index = calloc(1, sizeof(*index));
if (index == NULL) {
ret = -ENOMEM;
/* need to generate index for the table */
if (td->index_oid.oid_len) {
index = calloc(1, sizeof(*index));
if (index == NULL) {
ret = -ENOMEM;
ret = snmp_agent_register_oid_index(&idd->oids[i], *index,
snmp_agent_table_oid_handler);
else
ret = snmp_agent_register_oid_index(&idd->oids[i], *index,
snmp_agent_table_oid_handler);
else
ret = snmp_agent_register_oid_index(&dd->oids[i], *index,
snmp_agent_table_oid_handler);
else
ret = snmp_agent_register_oid_index(&dd->oids[i], *index,
snmp_agent_table_oid_handler);
else
else
snprintf(index_str, sizeof(index_str), "%d", *index);
else
snprintf(index_str, sizeof(index_str), "%d", *index);
remove_avl_index:
if (td->index_oid.oid_len)
c_avl_remove(td->index_instance, index, NULL, NULL);
remove_avl_index_oid:
remove_avl_index:
if (td->index_oid.oid_len)
c_avl_remove(td->index_instance, index, NULL, NULL);
remove_avl_index_oid:
- c_avl_remove(td->instance_index, *index_oid, NULL, NULL);
+ c_avl_remove(td->instance_index, index_oid, NULL, NULL);
if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) {
oid_t *index_oid = calloc(1, sizeof(*index_oid));
if (CHECK_DD_TYPE(dd, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) {
oid_t *index_oid = calloc(1, sizeof(*index_oid));
- ret = snmp_agent_update_index(dd, td, &index_oid);
+ ret = snmp_agent_update_index(dd, td, index_oid, &free_index_oid);
+
+ /* Index exists or update failed */
+ if (free_index_oid)
+ sfree(index_oid);