Reply to topic  [ 3 posts ] 
funcdef does not properly parse empty string 
Author Message
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post funcdef does not properly parse empty string
It appears that funcdef is not properly parsing empty strings:

Code:
> funcdef("write \"a\"")
a
> funcdef("write \"\"")
\"
> funcdef("write \"\\\"\"")
\"
> funcdef("funcset foo \"a\"")
> foo
"a"
> funcdef("funcset foo \"\"")
> foo
"\""
> funcdef("funcset foo \"\\\"\"")
> foo
"\""


Fri Sep 28, 2012 8:43 am
Profile
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Post Re: funcdef does not properly parse empty string
Wow, I actually figured out what's causing the issue, and I even figured out how to fix it (though I'm not sure I fixed it in the best way).

The code for funcdef was calling p_strncat with a length ("n") of 0. When p_strncat is given a length of 0, it replaces it with the length of the second string it's given (in this case, the input string) which it calculates with strlen, which calculates it by looking for a null character. In this case, that means it was picking up the following double-quote since the null string came after that.

My fix is to replace the closing double-quote with a null so that strlen will calculate the right length if it is called.

I went ahead and make this fix on my fork and put in a pull request. This doesn't feel like the cleanest way to handle it, though; I don't like modifying the input data.


Fri Sep 28, 2012 9:25 am
Profile
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Post Re: funcdef does not properly parse empty string
The fix was incorrect, but the bug is confirmed and fixed properly. Thank you very much.


Sun Sep 30, 2012 2:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.