Menu

#291 Line continuations inside strings can corrupt the postings file

open
nobody
None
5
2015-07-28
2015-07-28
Paul Bolle
No

0) Line continuations inside strings end up verbatim in the xref db. See, for example, the rule for '\\n' for 'IN_DQUOTE' and 'IN_SQUOTE' in src/fscanner.l. So both the backslash and the newline end up in the xref db.

1) This is on itself not a problem. Mainly because, as far as I can see, putline() will filter out the newline when that string will be printed.

2) However, things go awry when the xref db is updated, for instance if another file was changed. cscope will then try to regenerate the postings file from the xref db. But, when doing that, copyinverted() might mark the continued lines as symbols.

3) So lines like these can end up in the cscope.1 temporary file:
Current Driver Queue Depth: %d\n\ !!!%> y
Currently Allocated CCBs: %d\n", !!!%> y
Target Tagged Queuing Queue Depth Active Attempted Completed\n\ !!!&p y
Target Read Commands Write Commands Total Bytes Read Total Bytes Written\n\ !!!-v y
Target Command 0-1KB 1-2KB 2-4KB 4-8KB 8-16KB\n\ !!!7~ y
Target Command 16-32KB 32-64KB 64-128KB 128-256KB 256KB+\n\ !!!@z y
Target Requested Completed Requested Completed Requested Completed\n\ !!!J" y

(This is from a test case based on drivers/scsi/BusLogic.c in a current Linux kernel.)

4) cscope will basically parse these lines like this:
symbol lineoffset mark functionoffset
====== ========== ==== ==============
Current Drive r Queue
Currently Alloc a CCBs:
Target Tagge d Queui
Target Read C Write
Target Comma n 0-1KB
Target Comma n 16-32
Target Reque s Compl

(I'm not sure whether the functionoffset is correct here, but that doesn't matter much.)

So that's seven "symbols" with an insanely high lineoffset and a bogus mark. "onesearch" queries in "linemode" for these "symbols" trigger one or more prints of
Lseek failed: Invalid argument

and some bogus output.

5) Would it help if we'd strip the newline from line continuations inside strings, say like this:

diff -up ./src/fscanner.l.cont ./src/fscanner.l
--- ./src/fscanner.l.cont 2011-06-29 17:47:59.000000000 +0200
+++ ./src/fscanner.l 2015-07-28 14:43:47.904254883 +0200
@@ -778,7 +778,8 @@ if{wsnl}( { / ignore 'if' /
goto more;
/
NOTREACHED /
}
-\\n { /
line continuation inside a string! /
+\\n { /
line continuation inside a string: skip newline! /
+ yyleng = 1;
myylineno++;
goto more;
/
NOTREACHED */

Light testing shows this to do the right thing when the postings file is regenerated.

6) Comments appreciated.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.