Bug 128 - [patch] Lexer doesn't handle escaped backslash at end of string.
[patch] Lexer doesn't handle escaped backslash at end of string.
Status: RESOLVED FIXED
Product: NSD
Classification: Unclassified
Component: Zonec Code
2.3.x
All All
: P2 minor
Assigned To: NSD team
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-01-24 15:05 CET by Tim Deegan
Modified: 2006-01-25 00:29 CET (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Deegan 2006-01-24 15:05:49 CET
The lexer doesn't see that \ only escapes " if it is not escaped itself -- that is, "This string ends with a backslash: \\" should be treated as a complete string, but the lexer thinks the closing quote is escaped.

----

To reproduce: start with a two-line file "example.zone":

example.com. 86400 IN SOA ns0.example.com. hostmaster.example.com. 2006012401 3600 1800 86400 86400
test.example.com. 86400 IN HINFO "one\\" "two"

Run "./zonec -o example.com. -f example.db - <example.zone".  This gives this error message, although it should accept the zone as valid:

<stdin>:2: error: syntax error
<stdin>:3: error: EOF inside quoted string
fatal flex scanner internal error--end of buffer missed

----

The fix that I'm using is to stop the lexer treating "\" by itself as a string character.  Then it will only accept "\" along with the first character it escapes.  That stops it breaking "\\" down as "_\_\" and forces it to see "_\\_". This patch will probably be mangled by the webform, but you get the idea:

--- nsd-2.3.3/zlexer.lex        2005-05-12 13:55:38.000000000 +0100
+++ nsd/zlexer.lex      2006-01-24 13:40:13.000000000 +0000
@@ -78,7 +78,7 @@
 COMMENT ;
 DOT     \.
 BIT    [^\]\n]|\\.
-ANY     [^\"\n]|\\.
+ANY     [^\"\n\\]|\\.
 
 %x     incl bitlabel quotedstring
Comment 1 Wouter Wijngaards 2006-01-24 17:25:25 CET
Fixed, patch applied in code repository. Alternate cases "\\aa" and "aa\\bb" do not work yet.
Comment 2 Wouter Wijngaards 2006-01-25 00:29:32 CET
Oops. The test had a typo. Alternate cases work fine too.