@@ -520,7 +520,16 @@ Status Drivers::GatherScanInfo(const std::string &scan_path) {
520
520
}
521
521
522
522
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
+ }
524
533
525
534
auto driver_json_arr = dump_json[" scan_drivers" ];
526
535
for (auto &driver_info : driver_json_arr) {
@@ -555,8 +564,22 @@ void Drivers::FillCheckInfo(std::string &file_check_node,
555
564
std::unordered_map<std::string, bool > &file_map,
556
565
int64_t &ld_cache_time) {
557
566
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
+
558
572
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
+
560
583
file_check_node = dump_json[" check_code" ];
561
584
ld_cache_time = dump_json[" ld_cache_time" ];
562
585
auto driver_json_arr = dump_json[" scan_drivers" ];
@@ -671,10 +694,19 @@ void Drivers::PrintScanResults(const std::string &scan_path) {
671
694
std::ifstream scan_info_file (scan_path);
672
695
if (!scan_info_file.is_open ()) {
673
696
MBLOG_ERROR << " Open file " << scan_path << " for read failed" ;
697
+ return ;
674
698
}
675
699
676
700
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
+ }
678
710
679
711
nlohmann::json dump_driver_json_arr = nlohmann::json::array ();
680
712
dump_driver_json_arr = dump_json[" scan_drivers" ];
0 commit comments