summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-09 21:51:05 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-09 21:51:05 -0700
commit570a4cd9315f1a2189cb6d1877aa13a78ec00f0a (patch)
tree0e73977f4734902cd91ceb26ebb099feec0eb175
parent6ce1525fee353cd85ce9e8a1f76be29fd390b5ae (diff)
downloadtxr-570a4cd9315f1a2189cb6d1877aa13a78ec00f0a.tar.gz
txr-570a4cd9315f1a2189cb6d1877aa13a78ec00f0a.tar.bz2
txr-570a4cd9315f1a2189cb6d1877aa13a78ec00f0a.zip
Fix gc safety issue in abs_path_p function.
* stream.c (ap_regex): New static variable. (abs_path_p): Remove local reg variable; replace uses of reg with ap_regex. (stream_init): gc-protect ap_regex.
-rw-r--r--ChangeLog9
-rw-r--r--stream.c11
2 files changed, 16 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 8fa0faf5..19a8586d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
12014-10-09 Kaz Kylheku <kaz@kylheku.com> 12014-10-09 Kaz Kylheku <kaz@kylheku.com>
2 2
3 Fix gc safety issue in abs_path_p function.
4
5 * stream.c (ap_regex): New static variable.
6 (abs_path_p): Remove local reg variable; replace
7 uses of reg with ap_regex.
8 (stream_init): gc-protect ap_regex.
9
102014-10-09 Kaz Kylheku <kaz@kylheku.com>
11
3 * stream.c (stream_init): No need to gc-protect 12 * stream.c (stream_init): No need to gc-protect
4 std_input, std_output, std_debug, std_error and std_null. These are 13 std_input, std_output, std_debug, std_error and std_null. These are
5 not ordinary variables but macros which expand to locations in the 14 not ordinary variables but macros which expand to locations in the
diff --git a/stream.c b/stream.c
index 958ba9d5..48943fb4 100644
--- a/stream.c
+++ b/stream.c
@@ -2527,9 +2527,10 @@ static val open_files_star(val file_list, val substitute_stream)
2527 } 2527 }
2528} 2528}
2529 2529
2530static val ap_regex;
2531
2530val abs_path_p(val path) 2532val abs_path_p(val path)
2531{ 2533{
2532 static val reg;
2533 val ch; 2534 val ch;
2534 2535
2535 if (length(path) == zero) 2536 if (length(path) == zero)
@@ -2537,10 +2538,10 @@ val abs_path_p(val path)
2537 if ((ch = chr_str(path, zero)) == chr('/') || ch == chr('\\')) 2538 if ((ch = chr_str(path, zero)) == chr('/') || ch == chr('\\'))
2538 return t; 2539 return t;
2539 2540
2540 if (!reg) 2541 if (!ap_regex)
2541 reg = regex_compile(lit("[A-Za-z0-9]+:[/\\\\]"), nil); 2542 ap_regex = regex_compile(lit("[A-Za-z0-9]+:[/\\\\]"), nil);
2542 2543
2543 if (match_regex(path, reg, zero)) 2544 if (match_regex(path, ap_regex, zero))
2544 return t; 2545 return t;
2545 2546
2546 return nil; 2547 return nil;
@@ -2548,6 +2549,8 @@ val abs_path_p(val path)
2548 2549
2549void stream_init(void) 2550void stream_init(void)
2550{ 2551{
2552 prot1(&ap_regex);
2553
2551 detect_format_string(); 2554 detect_format_string();
2552 2555
2553 dev_k = intern(lit("dev"), keyword_package); 2556 dev_k = intern(lit("dev"), keyword_package);