Re: asn1.c/asn_parse_string() null-termination behaviour

This is a discussion on Re: asn1.c/asn_parse_string() null-termination behaviour within the SNMP Coders forums, part of the Networking and Network Related category; Robert Story wrote: > On Thu, 15 Jun 2006 12:41:36 +0200 Gustaf wrote: > GG> The problem ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Coders

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-16-2006
Gustaf Gunnarsson
 
Posts: n/a
Default Re: asn1.c/asn_parse_string() null-termination behaviour

Robert Story wrote:
> On Thu, 15 Jun 2006 12:41:36 +0200 Gustaf wrote:
> GG> The problem I am having is that the asn_parse_string() function
> GG> null-terminates the string it parses if the size of the recieving char*
> GG> is large enough to contain such terminator.
> GG>
> GG> I think this behaivour is wrong and that the returned string should
> GG> always be null-terminated (or never).
>
> The correct answer is never, since ASN strings are not null terminated.
> However, if the buffer is large enough, we do add a null because so many
> people think they are null terminated and pass them to printf and friends.
> It's just a little additional safety.


I really think this is wrong.

The reason why I think it is wrong is exactly what you mention, people
will pass this string to printf() since it works. I however think it
would be a lot better if people would learn the first time to do
something like:

asn1p = asn_parse_string(asn1p, &asn1p_len,
&asn1p_type, string, &string_len_MINUS_ONE);
*(string+&string_len_MINUS_ONE) = '\0';

Instead of having to figure out that this is what they need to do the
2784117371 time they run it and the program segfaults in their face
(without a clue why it happened).

Anyways, I am not going to argue about it (more than this :P).

Thanks for your answer.

//Gustaf



_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:22 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0