Skip to content

Commit 177bf5e

Browse files
committed
fix #142570: check file type before skipping the source first line
1 parent a154c9e commit 177bf5e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Modules/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
380380
return 2;
381381
}
382382

383+
struct _Py_stat_struct sb;
384+
if (_Py_fstat_noraise(fileno(fp), &sb) == 0 && S_ISDIR(sb.st_mode)) {
385+
PySys_FormatStderr("%S: %R is a directory, cannot continue\n",
386+
program_name, filename);
387+
fclose(fp);
388+
return 1;
389+
}
390+
383391
if (skip_source_first_line) {
384392
int ch;
385393
/* Push back first newline so line numbers remain the same */
@@ -391,14 +399,6 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
391399
}
392400
}
393401

394-
struct _Py_stat_struct sb;
395-
if (_Py_fstat_noraise(fileno(fp), &sb) == 0 && S_ISDIR(sb.st_mode)) {
396-
PySys_FormatStderr("%S: %R is a directory, cannot continue\n",
397-
program_name, filename);
398-
fclose(fp);
399-
return 1;
400-
}
401-
402402
// Call pending calls like signal handlers (SIGINT)
403403
if (Py_MakePendingCalls() == -1) {
404404
fclose(fp);

0 commit comments

Comments
 (0)