@ 260915.5

260421.2 · a02246554e9a811706f34108a1b168acd1c20998

tidy up

verify config file in the working directory; remove redundant logic; tidy up some comments

reading declarations

include/reflex/input.h

@@ -632,7 +632,7 @@ class Input {       return static_cast<unsigned char>(c);     return EOF;   }-  /// Copy character sequence data into buffer.+  /// Read and copy input character sequence data into buffer.   size_t get(       char  *s, ///< points to the string buffer to fill with input       size_t n) ///< size of buffer pointed to by s

lib/simd_avx2.cpp

@@ -78,7 +78,7 @@ size_t simd_nlcount_avx2(const char *& b, const char *e) #endif } -// Partially check if valid UTF-8 encoding+// Check if valid UTF-8 encoding and does not include a NUL, but pass surrogates and 3/4 byte overlongs bool simd_isutf8_avx2(const char *& b, const char *e) { #if defined(HAVE_AVX2) || defined(HAVE_AVX512BW)

src/ugrep.cpp

@@ -2281,11 +2281,8 @@ struct Grep {      size_t operator()(FILE*, char *buf, size_t len)     {-      if (!flag_text && !flag_hex && !flag_with_hex && flag_encoding_type != reflex::Input::file_encoding::null_data && !grep.binfile)-      {-        // simpler form of binary file detection without Unicode UTF-8 validation, check for NULs like GNU grep-        grep.binfile = (memchr(buf, 0, len) != NULL);-      }+      // simpler form of binary file detection without Unicode UTF-8 validation, check for NULs like GNU grep+      grep.binfile = grep.binfile || (memchr(buf, 0, len) != NULL);        return len;     }@@ -3996,9 +3993,9 @@ struct Grep {         if (init_is_binary())           return false;       }-      else if (!flag_quiet && !flag_files_with_matches && !flag_count && flag_format == NULL && !flag_text && !flag_hex && !flag_with_hex)+      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)       {-        // not -q, -l, -c, --format, -a -X, -W: check if initial part of the file is binary+        // not -q, -l, -c, --format, -a, -X, -W, -00: check if initial part of the file is binary         binfile = init_is_binary();          // 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_   std::string config_file(flag_config);   FILE *file = NULL; -  if (home || fopen_smart(&file, flag_config, "r") != 0)+  if (!home)   {-    file = NULL;+    // try opening a config file in the working directory+    if (fopen_smart(&file, flag_config, "r") == 0)+    {+#ifndef OS_WIN+      if (file != NULL && file != stdin)+      {+        // check if we own this config file located in the working directory+        struct stat buf;+        if (fstat(fileno(file), &buf) == 0 && buf.st_uid != getuid())+        {+          fclose(file);+          file = NULL;+        }+      }+#endif+    }+    else+    {+      file = NULL;+    }+  } +  if (file == NULL)+  {     // if not in the working directory, then check the home directory     if (Static::home_dir != NULL && *flag_config != '~' && *flag_config != PATHSEPCHR)     {