This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] do_line() crash
- From: Devang Patel <dpatel at apple dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 27 Feb 2005 12:03:14 -0800
- Subject: [PATCH] do_line() crash
It is possible that skip_rest_of_line() may cause line tables to be
reallocated and hence memory access crash later on by accessing old
pointer. This was reported by one of the customer and it requires huge
preprocessed source to trigger this.
Radar 3982899
* directives.c (do_line): Save sysp early before line table is
realloc'ed.
Bootstrapped and tested on powerpc-darwin.
Geoff has OK'ed this for mainline.
OK for 4.0 also?
Thanks,
-
Devang
Index: directives.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/directives.c,v
retrieving revision 1.12
diff -Idpatel.pbxuser -c -3 -p -r1.12 directives.c
*** directives.c 14 Feb 2005 14:43:56 -0000 1.12
--- directives.c 27 Feb 2005 19:59:06 -0000
*************** do_line (cpp_reader *pfile)
*** 775,780 ****
--- 775,785 ----
{
const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = &line_table->maps[line_table->used -
1];
+
+ /* skip_rest_of_line() may cause line table to be realloc()ed so
note down
+ sysp right now. */
+
+ unsigned char map_sysp = map->sysp;
const cpp_token *token;
const char *new_file = map->to_file;
unsigned long new_lineno;
*************** do_line (cpp_reader *pfile)
*** 815,821 ****
skip_rest_of_line (pfile);
_cpp_do_file_change (pfile, LC_RENAME, new_file, new_lineno,
! map->sysp);
}
/* Interpret the # 44 "file" [flags] notation, which has slightly
--- 820,826 ----
skip_rest_of_line (pfile);
_cpp_do_file_change (pfile, LC_RENAME, new_file, new_lineno,
! map_sysp);
}
/* Interpret the # 44 "file" [flags] notation, which has slightly