File tree 1 file changed +13
-7
lines changed
1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -1125,19 +1125,26 @@ int TIDY_CALL tidyParseSource( TidyDoc tdoc, TidyInputSource* source )
1125
1125
return tidyDocParseSource ( doc , source );
1126
1126
}
1127
1127
1128
-
1128
+ #ifdef WIN32
1129
+ #define M_IS_DIR _S_IFDIR
1130
+ #else // !WIN32
1131
+ #define M_IS_DIR S_IFDIR
1132
+ #endif
1129
1133
int tidyDocParseFile ( TidyDocImpl * doc , ctmbstr filnam )
1130
1134
{
1131
1135
int status = - ENOENT ;
1132
- FILE * fin = fopen ( filnam , "r+" ) ;
1133
-
1134
- if ( ! fin )
1136
+ FILE * fin = 0 ;
1137
+ struct stat sbuf = { 0 }; /* Is. #681 - read-only files */
1138
+ if ( stat ( filnam , & sbuf ) != 0 )
1135
1139
{
1136
1140
TY_ (ReportFileError )( doc , filnam , FILE_NOT_FILE );
1137
1141
return status ;
1138
1142
}
1139
-
1140
- fclose ( fin );
1143
+ if (sbuf .st_mode & M_IS_DIR ) /* and /NOT/ if a DIRECTORY */
1144
+ {
1145
+ TY_ (ReportFileError )(doc , filnam , FILE_NOT_FILE );
1146
+ return status ;
1147
+ }
1141
1148
1142
1149
#ifdef _WIN32
1143
1150
return TY_ (DocParseFileWithMappedFile )( doc , filnam );
@@ -1147,7 +1154,6 @@ int tidyDocParseFile( TidyDocImpl* doc, ctmbstr filnam )
1147
1154
1148
1155
#if PRESERVE_FILE_TIMES
1149
1156
{
1150
- struct stat sbuf = { 0 };
1151
1157
/* get last modified time */
1152
1158
TidyClearMemory (& doc -> filetimes , sizeof (doc -> filetimes ));
1153
1159
if (fin && cfgBool (doc , TidyKeepFileTimes ) &&
You can’t perform that action at this time.
0 commit comments