-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: Drop use of trashbox and setjmp #138
Conversation
You missed two loops that can now become infinite: begin
if current publisher <> 'publish' then
signal UE_FailStatement and BEGIN
WHEN As I don't have push write on your branch (well, I didn't test but I shouldn't ^^) here's the diff: diff --git a/sql.c b/sql.c
index 4b6851c..6f0ca48 100644
--- a/sql.c
+++ b/sql.c
@@ -1292,7 +1292,8 @@ static void parseStatements (tokenInfo *const token, const boolean exit_on_endif
* of a nested BEGIN END block. So read the next token
* after the THEN and restart the LOOP.
*/
- while (! isKeyword (token, KEYWORD_then))
+ while (! isKeyword (token, KEYWORD_then) &&
+ ! isType (token, TOKEN_EOF))
readToken (token);
readToken (token);
@@ -1493,6 +1494,7 @@ static void parseStatements (tokenInfo *const token, const boolean exit_on_endif
*/
while ( ! stmtTerm &&
! ( isKeyword (token, KEYWORD_end) ||
+ isType (token, TOKEN_EOF) ||
(isCmdTerm(token)) )
)
{ Feel free to squash it into your commit or anything. |
a6c8006
to
442a4f4
Compare
Fixed bugs found by @b4n. |
I just quickly reviewed the new version and the changes look good to me. |
Still wanted to hear from @masatake because he also worked on this file lately. |
I'll review. |
How about this input with "ctags -o - -language-force=SQL FILE" ? |
*I cannot find the time for reviewing now. So I wrote here how my tool says)
|
Indeed, good catch. That's because of a convoluted test in while (! (isType (token, close_token) && (nest_level == 0) && !isType (token, TOKEN_EOF))) has the check for while (! (isType (token, close_token) && (nest_level == 0)) && !isType (token, TOKEN_EOF)) Although it could actually be written a lot simpler like this: while (nest_level > 0 && !isType (token, TOKEN_EOF)) as actually only a token of type |
Com'on @b4n! You have a fix before I am able to read the email? :P |
hehe :) BTW, I would think that such mistakes would be easier avoided by using more straightforward (IMO) test conditions in the loops, like instead of while ( ! stmtTerm &&
! ( isKeyword (token, KEYWORD_end) ||
(isCmdTerm(token)) ||
(isType(token, TOKEN_EOF)) )
) which, could more or less obviously be rewritten using only one kind of test: while ( ! stmtTerm &&
! isKeyword (token, KEYWORD_end) &&
! isCmdTerm(token) &&
! isType(token, TOKEN_EOF)) What do you think, should we clean up the tests in sql.c? |
Just noticed going through the tests that addition on line 1183 is redundant: only need to check for EOF in negative conditions (if it is a keyword it can't be EOF). However that's only a remark, maybe we still want to keep the check for EOF in all loops for future use (though, it wouldn't prevent somebody from writing a bad new loop). |
I should be able to spend some time on this tonight. |
Wait, I was giving it a look and ended up mostly doing it already :) If you could fix the bug spotted by @masatake in this PR, as it's introduced here, I could submit a second commit with proposed cleanup. |
If you have time, could you try http://www.srpmix.org/tmp/nano-fuzz ? There are some input for sql parser in our Units//input.. The can be used as the base input. I want to merge nano-fuzz to testing.mak. However, next two weeks, I will not have much time. If you got a crash or an infinite loop, use units shrink like
for debugging. @vhda, with quick reviewing I cannot find anything wrong. |
Add new token type to identify EOF and use it to break out of loops, properly cleaning all local memory allocations until parser terminates.
442a4f4
to
f44c0b2
Compare
@masatake sounds interesting indeed :) BTW, to quickly spot where the problem you found came from I just ran inside GDB and stopped the program when it went into the infinite loop. The stack trace was simple enough for me to spot the issue instantly -- so, also use GDB :) Also, I went through all tests to try and simplify them, and I couldn't find any other that looked wrong even after simplifying them, so I believe it's safe on this front now -- e.g. I'm quite confident this patch doesn't add new issues. |
@vhda good, thanks. Should we merge this first and I make a new PR, or should I make a new PR with your changes and mines, or would you like to pull mines in this one? |
sql: Drop use of trashbox and setjmp
Nevermind, I merged and opened #149 |
st: Import the latest code from Ruby
Add new token type to identify EOF and use it to break out of loops, properly
cleaning all local memory allocations until parser terminates.