[AGENT++] Small bug
Jochen Katz
katz at agentpp.com
Fri May 27 22:04:19 CEST 2005
Hi,
someone reported this a week ago and after some mails I think, this
function will be changed to:
int Vb::get_value(unsigned char *ptr, unsigned long &len,
const unsigned long maxlen,
const bool add_null_byte = false) const
So current code will not get a null byte, as the documentation of this
function always said.
If add_null_byte == true, a null byte will always be added and possibly
truncate the string if the buffer isn't big enough.
Any more comments or suggestions?
Don't expect a reply from me during the next two weeks, as I will be
here: http://en.wikipedia.org/wiki/Fuerteventura
Regards,
Jochen
Karl Abicht wrote:
> Hi,
>
> your code (vb.cpp):
>
> // get an unsigned char array
> // caller specifies max len of target space
> int Vb::get_value(unsigned char *ptr, unsigned long &len,
> const unsigned long maxlen) const
> {
> if (iv_vb_value &&
> iv_vb_value->valid() &&
> (iv_vb_value->get_syntax() == sNMP_SYNTAX_OCTETS))
> {
> OctetStr *p_os = (OctetStr *)iv_vb_value;
> len = p_os->len();
> if (len > maxlen) len = maxlen;
> memcpy(ptr, p_os->data(), len);
> ptr[len] = 0;
> return SNMP_CLASS_SUCCESS;
> }
>
> ptr[0] = 0;
> len = 0;
> return SNMP_CLASS_INVALID;
> }
>
>
> The line ptr[len] sometimes writes behind the allowed maxlen.
>
> len < maxlen ==> ok
> len == maxlen ==> trouble
> len > maxlen ==> trouble
>
>
> Regards
>
> Karl
>
More information about the AGENTPP
mailing list