@@ -520,7 +520,16 @@ Status Drivers::GatherScanInfo(const std::string &scan_path) {
520520 }
521521
522522 nlohmann::json dump_json;
523- scan_info_file >> dump_json;
523+ try {
524+ std::string ss ((std::istreambuf_iterator<char >(scan_info_file)),
525+ std::istreambuf_iterator<char >());
526+ dump_json = nlohmann::json::parse (ss);
527+
528+ } catch (const std::exception &e) {
529+ auto err_msg = " gather scan info failed, err: " + std::string (e.what ());
530+ MBLOG_ERROR << err_msg;
531+ return {STATUS_FAULT, err_msg};
532+ }
524533
525534 auto driver_json_arr = dump_json[" scan_drivers" ];
526535 for (auto &driver_info : driver_json_arr) {
@@ -555,8 +564,22 @@ void Drivers::FillCheckInfo(std::string &file_check_node,
555564 std::unordered_map<std::string, bool > &file_map,
556565 int64_t &ld_cache_time) {
557566 std::ifstream scan_info (DEFAULT_SCAN_INFO);
567+ if (!scan_info.is_open ()) {
568+ MBLOG_ERROR << " open " << DEFAULT_SCAN_INFO << " failed." ;
569+ return ;
570+ }
571+
558572 nlohmann::json dump_json;
559- scan_info >> dump_json;
573+ try {
574+ std::string ss ((std::istreambuf_iterator<char >(scan_info)),
575+ std::istreambuf_iterator<char >());
576+ dump_json = nlohmann::json::parse (ss);
577+ } catch (const std::exception &e) {
578+ MBLOG_ERROR << " filee check info parse " << DEFAULT_SCAN_INFO
579+ << " failed, err: " << e.what ();
580+ return ;
581+ }
582+
560583 file_check_node = dump_json[" check_code" ];
561584 ld_cache_time = dump_json[" ld_cache_time" ];
562585 auto driver_json_arr = dump_json[" scan_drivers" ];
@@ -671,10 +694,19 @@ void Drivers::PrintScanResults(const std::string &scan_path) {
671694 std::ifstream scan_info_file (scan_path);
672695 if (!scan_info_file.is_open ()) {
673696 MBLOG_ERROR << " Open file " << scan_path << " for read failed" ;
697+ return ;
674698 }
675699
676700 nlohmann::json dump_json;
677- scan_info_file >> dump_json;
701+ try {
702+ std::string ss ((std::istreambuf_iterator<char >(scan_info_file)),
703+ std::istreambuf_iterator<char >());
704+ dump_json = nlohmann::json::parse (ss);
705+
706+ } catch (const std::exception &e) {
707+ MBLOG_ERROR << " print scan result failed, err: " << e.what ();
708+ return ;
709+ }
678710
679711 nlohmann::json dump_driver_json_arr = nlohmann::json::array ();
680712 dump_driver_json_arr = dump_json[" scan_drivers" ];
0 commit comments