checks.cpp raw

   1  // Copyright (c) 2022 The Limenka developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #include <kernel/checks.h>
   6  
   7  #include <dbwrapper.h>
   8  #include <random.h>
   9  #include <util/result.h>
  10  #include <util/translation.h>
  11  
  12  #include <memory>
  13  
  14  namespace kernel {
  15  
  16  bool Clang_IndVarSimplify_Bug_SanityCheck() {
  17      // See https://github.com/llvm/llvm-project/issues/96267
  18      const char s[] = {0, 0x75};
  19      signed int last = 0xff;
  20      for (const char *it = s; it < &s[2]; ++it) {
  21          if (*it <= 0x4e) {
  22          } else if (*it == 0x75 && last <= 0x4e) {
  23              return true;
  24          }
  25          last = *it;
  26      }
  27      return false;
  28  }
  29  
  30  util::Result<void> SanityChecks(const Context&)
  31  {
  32      if (auto result{dbwrapper_SanityCheck()}; !result) {
  33          return util::Error{util::ErrorString(result) + Untranslated("\nDatabase sanity check failure. Aborting.")};
  34      }
  35  
  36      if (!Clang_IndVarSimplify_Bug_SanityCheck()) {
  37          return util::Error{Untranslated("Compiler optimization sanity check failure. Aborting.")};
  38      }
  39  
  40      if (!Random_SanityCheck()) {
  41          return util::Error{Untranslated("OS cryptographic RNG sanity check failure. Aborting.")};
  42      }
  43  
  44      return {};
  45  }
  46  
  47  }
  48