From 383df7c4409738283ac2cd8d972104353ddbd54c Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Tue, 19 Jun 2018 11:11:09 +0700 Subject: [PATCH] snmp_agent: Replace strndup() with internal implementation This adressed to fix Solaris 10 builds. Closes: #2814 --- src/snmp_agent.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 3c042a86..aeb01587 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -383,11 +383,20 @@ static int snmp_agent_create_token(char const *input, int t_off, int n, int ret = 0; token->key = index_key; - token->str = strndup(input + t_off, n); + /* copy at most n bytes from input with offset t_off into token->str */ + input += t_off; + size_t len = strlen(input); + if (n < len) + len = n; + + token->str = malloc(len + 1); if (token->str == NULL) goto free_offset_error; + memcpy(token->str, input, len); + token->str[len] = '\0'; + *offset = t_off; ret = c_avl_insert(tree, (void *)offset, (void *)token); -- 2.11.0