_Z23validateErrorsToMonitorRNSt3__16vectorINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS4_IS6_EEEE:
   11|  4.72k|{
   12|  4.72k|    if (errorsToMonitor.empty())
  ------------------
  |  Branch (12:9): [True: 1, False: 4.72k]
  ------------------
   13|      1|    {
   14|      1|        throw std::invalid_argument("errorsToMonitor must not be empty");
   15|      1|    }
   16|       |
   17|  4.72k|    const std::vector<std::string> validErrorsToMonitor = {
   18|  4.72k|        "default", "timeout", "failed", "dependency"};
   19|  4.72k|    for (const auto& errorToMonitor : errorsToMonitor)
  ------------------
  |  Branch (19:37): [True: 8.27k, False: 4.56k]
  ------------------
   20|  8.27k|    {
   21|  8.27k|        if (std::find(validErrorsToMonitor.begin(), validErrorsToMonitor.end(),
  ------------------
  |  Branch (21:13): [True: 160, False: 8.11k]
  ------------------
   22|  8.27k|                      errorToMonitor) == validErrorsToMonitor.end())
   23|    160|        {
   24|    160|            throw std::out_of_range("Found invalid error to monitor");
   25|    160|        }
   26|  8.27k|    }
   27|       |    // See if default was in the errors to monitor, if so replace with defaults
   28|  4.56k|    auto errorItr =
   29|  4.56k|        std::find(errorsToMonitor.begin(), errorsToMonitor.end(), "default");
   30|  4.56k|    if (errorItr != errorsToMonitor.end())
  ------------------
  |  Branch (30:9): [True: 3.07k, False: 1.49k]
  ------------------
   31|  3.07k|    {
   32|       |        // Verify default is the only entry
   33|  3.07k|        if (errorsToMonitor.size() != 1)
  ------------------
  |  Branch (33:13): [True: 7, False: 3.06k]
  ------------------
   34|      7|        {
   35|      7|            throw std::invalid_argument(
   36|      7|                "default must be only error to monitor");
   37|      7|        }
   38|       |        // delete "default" and insert defaults
   39|  3.06k|        errorsToMonitor.erase(errorItr);
   40|  3.06k|        errorsToMonitor.emplace_back("timeout");
   41|  3.06k|        errorsToMonitor.emplace_back("failed");
   42|  3.06k|        errorsToMonitor.emplace_back("dependency");
   43|  3.06k|    }
   44|  4.56k|}
_Z10parseFilesRKNSt3__16vectorINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS4_IS6_EEEE:
   47|  4.73k|{
   48|  4.73k|    TargetErrorData systemdTargetMap;
   49|  4.73k|    for (const auto& jsonFile : filePaths)
  ------------------
  |  Branch (49:31): [True: 4.73k, False: 4.73k]
  ------------------
   50|  4.73k|    {
   51|  4.73k|        if (gVerbose)
  ------------------
  |  Branch (51:13): [True: 0, False: 4.73k]
  ------------------
   52|      0|        {
   53|      0|            debug("Parsing input file {FILE}", "FILE", jsonFile);
   54|      0|        }
   55|  4.73k|        std::ifstream fileStream(jsonFile);
   56|  4.73k|        if (!fileStream.is_open())
  ------------------
  |  Branch (56:13): [True: 0, False: 4.73k]
  ------------------
   57|      0|        {
   58|      0|            error("Failed to open target monitor file: {FILE}", "FILE",
   59|      0|                  jsonFile);
   60|      0|            continue;
   61|      0|        }
   62|  4.73k|        auto j = json::parse(fileStream);
   63|       |
   64|  9.58k|        for (auto it = j["targets"].begin(); it != j["targets"].end(); ++it)
  ------------------
  |  Branch (64:46): [True: 4.84k, False: 4.73k]
  ------------------
   65|  4.84k|        {
   66|  4.84k|            targetEntry entry;
   67|  4.84k|            if (gVerbose)
  ------------------
  |  Branch (67:17): [True: 0, False: 4.84k]
  ------------------
   68|      0|            {
   69|      0|                debug("target: {KEY} | {VALUE}", "KEY", it.key(), "VALUE",
   70|      0|                      it.value());
   71|      0|            }
   72|       |
   73|       |            // Be unforgiving on invalid json files. Just throw or allow
   74|       |            // nlohmann to throw an exception if something is off
   75|  4.84k|            entry.errorsToMonitor = it.value()
   76|  4.84k|                                        .at("errorsToMonitor")
   77|  4.84k|                                        .get<std::vector<std::string>>();
   78|       |
   79|  4.84k|            validateErrorsToMonitor(entry.errorsToMonitor);
   80|       |
   81|  4.84k|            entry.errorToLog = it.value().at("errorToLog").get<std::string>();
   82|       |
   83|  4.84k|            systemdTargetMap[it.key()] = entry;
   84|  4.84k|        }
   85|  4.73k|    }
   86|  4.73k|    return systemdTargetMap;
   87|  4.73k|}

LLVMFuzzerTestOneInput:
   27|  4.73k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   28|       |    // Write data to a temporary file
   29|  4.73k|    char temp_filename[] = "/tmp/target_parser_fuzzer_XXXXXX";
   30|  4.73k|    int fd = mkstemp(temp_filename);
   31|  4.73k|    if (fd < 0) {
  ------------------
  |  Branch (31:9): [True: 0, False: 4.73k]
  ------------------
   32|      0|        return 0;
   33|      0|    }
   34|       |    
   35|  4.73k|    if (write(fd, data, size) != static_cast<ssize_t>(size)) {
  ------------------
  |  Branch (35:9): [True: 0, False: 4.73k]
  ------------------
   36|      0|        close(fd);
   37|      0|        unlink(temp_filename);
   38|      0|        return 0;
   39|      0|    }
   40|  4.73k|    close(fd);
   41|       |
   42|       |    // Call the function under test
   43|  4.73k|    try {
   44|  4.73k|        std::vector<std::string> filePaths = {temp_filename};
   45|  4.73k|        parseFiles(filePaths);
   46|  4.73k|    } catch (const std::exception& e) {
   47|       |        // We expect exceptions for invalid JSON or validation errors,
   48|       |        // which is fine. We want to catch them so the fuzzer doesn't
   49|       |        // treat them as crashes.
   50|  4.40k|    }
   51|       |
   52|       |    // Clean up
   53|  4.73k|    unlink(temp_filename);
   54|  4.73k|    return 0;
   55|  4.73k|}

