@@ -2281,11 +2281,8 @@ struct Grep {
22812281
22822282 size_t operator()(FILE*, char *buf, size_t len)
22832283 {
2284- if (!flag_text && !flag_hex && !flag_with_hex && flag_encoding_type != reflex::Input::file_encoding::null_data && !grep.binfile)
2285- {
2286- // simpler form of binary file detection without Unicode UTF-8 validation, check for NULs like GNU grep
2287- grep.binfile = (memchr(buf, 0, len) != NULL);
2288- }
2284+ // simpler form of binary file detection without Unicode UTF-8 validation, check for NULs like GNU grep
2285+ grep.binfile = grep.binfile || (memchr(buf, 0, len) != NULL);
22892286
22902287 return len;
22912288 }
@@ -3996,9 +3993,9 @@ struct Grep {
39963993 if (init_is_binary())
39973994 return false;
39983995 }
3999- else if (!flag_quiet && !flag_files_with_matches && !flag_count && flag_format == NULL && !flag_text && !flag_hex && !flag_with_hex)
3996+ else if (!flag_quiet && !flag_files_with_matches && !flag_count && flag_format == NULL && !flag_text && !flag_hex && !flag_with_hex && flag_encoding_type != reflex::Input::file_encoding::null_data )
40003997 {
4001- // not -q, -l, -c, --format, -a -X, -W: check if initial part of the file is binary
3998+ // not -q, -l, -c, --format, -a, -X, -W, -00 : check if initial part of the file is binary
40023999 binfile = init_is_binary();
40034000
40044001 // detect binary input dynamically when more input is read after checking the inital input
@@ -4809,10 +4806,32 @@ static void load_config(std::list<std::pair<CNF::PATTERN,const char*>>& pattern_
48094806 std::string config_file(flag_config);
48104807 FILE *file = NULL;
48114808
4812- if (home || fopen_smart(&file, flag_config, "r") != 0 )
4809+ if (!home )
48134810 {
4814- file = NULL;
4811+ // try opening a config file in the working directory
4812+ if (fopen_smart(&file, flag_config, "r") == 0)
4813+ {
4814+ #ifndef OS_WIN
4815+ if (file != NULL && file != stdin)
4816+ {
4817+ // check if we own this config file located in the working directory
4818+ struct stat buf;
4819+ if (fstat(fileno(file), &buf) == 0 && buf.st_uid != getuid())
4820+ {
4821+ fclose(file);
4822+ file = NULL;
4823+ }
4824+ }
4825+ #endif
4826+ }
4827+ else
4828+ {
4829+ file = NULL;
4830+ }
4831+ }
48154832
4833+ if (file == NULL)
4834+ {
48164835 // if not in the working directory, then check the home directory
48174836 if (Static::home_dir != NULL && *flag_config != '~' && *flag_config != PATHSEPCHR)
48184837 {
0 commit comments