diff options
| author | Paul Eggert | 2019-07-31 10:38:34 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-07-31 10:41:21 -0700 |
| commit | 3018f6d832907e0321e90ba27397200e56fe5957 (patch) | |
| tree | e26fb329c168b329283385ae9a940734fd0df16c /src | |
| parent | 06726f6653fd2be9e33552209fceddd352a62793 (diff) | |
| download | emacs-3018f6d832907e0321e90ba27397200e56fe5957.tar.gz emacs-3018f6d832907e0321e90ba27397200e56fe5957.zip | |
Fix Fload infile problem
* src/lread.c (Fload): Close window of vulnerability
where the wrong stream could have been closed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lread.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/lread.c b/src/lread.c index 2c0c18dd798..eec88760d42 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -1083,7 +1083,7 @@ static void | |||
| 1083 | close_infile_unwind (void *arg) | 1083 | close_infile_unwind (void *arg) |
| 1084 | { | 1084 | { |
| 1085 | struct infile *prev_infile = arg; | 1085 | struct infile *prev_infile = arg; |
| 1086 | eassert (infile); | 1086 | eassert (infile && infile != prev_infile); |
| 1087 | fclose (infile->stream); | 1087 | fclose (infile->stream); |
| 1088 | infile = prev_infile; | 1088 | infile = prev_infile; |
| 1089 | } | 1089 | } |
| @@ -1403,6 +1403,10 @@ Return t if the file exists and loads successfully. */) | |||
| 1403 | #endif | 1403 | #endif |
| 1404 | } | 1404 | } |
| 1405 | 1405 | ||
| 1406 | /* Declare here rather than inside the else-part because the storage | ||
| 1407 | might be accessed by the unbind_to call below. */ | ||
| 1408 | struct infile input; | ||
| 1409 | |||
| 1406 | if (is_module) | 1410 | if (is_module) |
| 1407 | { | 1411 | { |
| 1408 | /* `module-load' uses the file name, so we can close the stream | 1412 | /* `module-load' uses the file name, so we can close the stream |
| @@ -1418,6 +1422,9 @@ Return t if the file exists and loads successfully. */) | |||
| 1418 | if (! stream) | 1422 | if (! stream) |
| 1419 | report_file_error ("Opening stdio stream", file); | 1423 | report_file_error ("Opening stdio stream", file); |
| 1420 | set_unwind_protect_ptr (fd_index, close_infile_unwind, infile); | 1424 | set_unwind_protect_ptr (fd_index, close_infile_unwind, infile); |
| 1425 | input.stream = stream; | ||
| 1426 | input.lookahead = 0; | ||
| 1427 | infile = &input; | ||
| 1421 | } | 1428 | } |
| 1422 | 1429 | ||
| 1423 | if (! NILP (Vpurify_flag)) | 1430 | if (! NILP (Vpurify_flag)) |
| @@ -1443,10 +1450,6 @@ Return t if the file exists and loads successfully. */) | |||
| 1443 | specbind (Qinhibit_file_name_operation, Qnil); | 1450 | specbind (Qinhibit_file_name_operation, Qnil); |
| 1444 | specbind (Qload_in_progress, Qt); | 1451 | specbind (Qload_in_progress, Qt); |
| 1445 | 1452 | ||
| 1446 | /* Declare here rather than inside the else-part because the storage | ||
| 1447 | might be accessed by the unbind_to call below. */ | ||
| 1448 | struct infile input; | ||
| 1449 | |||
| 1450 | if (is_module) | 1453 | if (is_module) |
| 1451 | { | 1454 | { |
| 1452 | #ifdef HAVE_MODULES | 1455 | #ifdef HAVE_MODULES |
| @@ -1461,10 +1464,6 @@ Return t if the file exists and loads successfully. */) | |||
| 1461 | } | 1464 | } |
| 1462 | else | 1465 | else |
| 1463 | { | 1466 | { |
| 1464 | input.stream = stream; | ||
| 1465 | input.lookahead = 0; | ||
| 1466 | infile = &input; | ||
| 1467 | |||
| 1468 | if (lisp_file_lexically_bound_p (Qget_file_char)) | 1467 | if (lisp_file_lexically_bound_p (Qget_file_char)) |
| 1469 | Fset (Qlexical_binding, Qt); | 1468 | Fset (Qlexical_binding, Qt); |
| 1470 | 1469 | ||