mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-03 10:53:23 +00:00
etags: fix #line parsing (\\", long lines)
* lib-src/etags.c (readline): Don’t mishandle lines like ‘#line 1 "a//"’, which has an escaped backslash before ‘"’. Don’t mishandle lines so long that sscanf overflows %n.
This commit is contained in:
parent
de59c02c68
commit
7e2309c6fc
1 changed files with 11 additions and 11 deletions
|
@ -7375,26 +7375,26 @@ readline (linebuffer *lbp, FILE *stream)
|
||||||
/* Check whether this is a #line directive. */
|
/* Check whether this is a #line directive. */
|
||||||
if (result > 12 && strneq (lbp->buffer, "#line ", 6))
|
if (result > 12 && strneq (lbp->buffer, "#line ", 6))
|
||||||
{
|
{
|
||||||
intmax_t lno;
|
char *lno_start = lbp->buffer + 6;
|
||||||
int start = 0;
|
char *lno_end;
|
||||||
|
intmax_t lno = strtoimax (lno_start, &lno_end, 10);
|
||||||
|
char *quoted_filename
|
||||||
|
= lno_start < lno_end ? skip_spaces (lno_end) : NULL;
|
||||||
|
|
||||||
if (sscanf (lbp->buffer, "#line %"SCNdMAX" \"%n", &lno, &start) >= 1
|
if (quoted_filename && *quoted_filename == '"')
|
||||||
&& start > 0) /* double quote character found */
|
|
||||||
{
|
{
|
||||||
char *endp = lbp->buffer + start;
|
char *endp = quoted_filename;
|
||||||
|
while (*++endp && *endp != '"')
|
||||||
|
endp += *endp == '\\' && endp[1];
|
||||||
|
|
||||||
while ((endp = strchr (endp, '"')) != NULL
|
if (*endp)
|
||||||
&& endp[-1] == '\\')
|
|
||||||
endp++;
|
|
||||||
if (endp != NULL)
|
|
||||||
/* Ok, this is a real #line directive. Let's deal with it. */
|
/* Ok, this is a real #line directive. Let's deal with it. */
|
||||||
{
|
{
|
||||||
char *taggedabsname; /* absolute name of original file */
|
char *taggedabsname; /* absolute name of original file */
|
||||||
char *taggedfname; /* name of original file as given */
|
char *taggedfname; /* name of original file as given */
|
||||||
char *name; /* temp var */
|
char *name = quoted_filename + 1;
|
||||||
|
|
||||||
discard_until_line_directive = false; /* found it */
|
discard_until_line_directive = false; /* found it */
|
||||||
name = lbp->buffer + start;
|
|
||||||
*endp = '\0';
|
*endp = '\0';
|
||||||
canonicalize_filename (name);
|
canonicalize_filename (name);
|
||||||
taggedabsname = absolute_filename (name, tagfiledir);
|
taggedabsname = absolute_filename (name, tagfiledir);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue