Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the static scan issues #311

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/guest/aaf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void Aaf::Flush(void) {
if (tmp.empty())
continue;
std::string key = tmp.substr(0, tmp.find(":"));

if (key.length() == 0)
continue;
auto find = data_.find(key);
if ((find != data_.end()) && !find->second.empty()) {
out << key << ":" << find->second << "\n";
Expand Down
4 changes: 1 addition & 3 deletions src/guest/config_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ bool CivConfig::SanitizeOpts(void) {
if (group != kConfigMap.end()) {
for (auto& subsec : section.second) {
auto key = std::find(group->second.begin(), group->second.end(), subsec.first);
if (key != group->second.end()) {
continue;
} else {
if (key == group->second.end()) {
LOG(error) << "Invalid key: " << section.first << "." << subsec.first << "\n";
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/guest/tui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ void CivTui::SetConfToPtree() {
std::string passthrough;
for (std::vector<std::string>::iterator iter = pt_pci_disp_.begin(); iter != pt_pci_disp_.end(); iter++) {
std::string selectItem = *iter;
if (selectItem.length() < 0)
continue;
size_t pos = selectItem.find(" ");
if (pos < 0)
continue;
passthrough += selectItem.substr(0, pos);
if (iter != (pt_pci_disp_.end() - 1)) {
passthrough += ',';
Expand Down
2 changes: 1 addition & 1 deletion src/guest/vm_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VmBuilder {
};

public:
explicit VmBuilder(std::string name) : name_(name) {}
explicit VmBuilder(std::string name) : name_(name), vsock_cid_(0) {}
virtual ~VmBuilder() = default;
virtual bool BuildVmArgs(void) = 0;
virtual void StartVm(void) = 0;
Expand Down
7 changes: 3 additions & 4 deletions src/guest/vm_flash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,14 @@ bool VmFlasher::FlashGuest(std::string path) {

if (!cfg_.ReadConfigFile(p.string())) {
LOG(error) << "Failed to read config file";
return -1;
return false;
}

std::string emul_type = cfg_.GetValue(kGroupEmul, kEmulType);
if (emul_type.compare(kEmulTypeQemu) == 0) {
return FlashWithQemu();
} else {
if ((emul_type.compare(kEmulTypeQemu) == 0) || emul_type.empty()) {
return FlashWithQemu();
}
return false;
}

} // namespace vm_manager
7 changes: 7 additions & 0 deletions src/guest/vm_process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ void VmProcSimple::ThreadMon(void) {

boost::process::environment env;
for (std::string s : env_data_) {
if (s.length() == 0)
continue;
env.set(s.substr(0, s.find('=')), s.substr(s.find('=') + 1));
}

LOG(info) << "CMD: " << cmd_;
size_t exe_pos_begin = cmd_.find_first_not_of(' ');
if (exe_pos_begin == std::string::npos)
return;

size_t exe_pos_end = cmd_.find_first_of(' ', exe_pos_begin);
if (exe_pos_end == std::string::npos)
exe_pos_end = cmd_.size();
std::string exe = cmd_.substr(exe_pos_begin, exe_pos_end - exe_pos_begin);

std::string tid = boost::lexical_cast<std::string>(mon_->get_id());
Expand Down
3 changes: 1 addition & 2 deletions src/host/app_launcher/app_launcher_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ class AppLauncherOptions final {
return true;
}

uint32_t cid = -1;
if (vm_.count("cid") != 1) {
PrintHelp();
return false;
}
cid = vm_["cid"].as<uint32_t>();
uint32_t cid = vm_["cid"].as<uint32_t>();

std::string app_name;
if (vm_.count("name") != 1) {
Expand Down
11 changes: 10 additions & 1 deletion src/services/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <string>
#include <vector>
#include <utility>
#include <cassert>

#include <boost/process/environment.hpp>

Expand Down Expand Up @@ -43,6 +44,9 @@ void Client::PrepareStartGuestClientShm(const char *path) {
[env.size()]
(client_shm_.get_segment_manager());

if (!var_env)
return;

for (std::string s : env._data) {
var_env->assign(s.c_str());
var_env++;
Expand Down Expand Up @@ -73,6 +77,7 @@ CivVmInfo Client::GetCivVmInfo(const char *vm_name) {
CivVmInfo *vm_info = client_shm_.find_or_construct<CivVmInfo>
("VmInfo")
(0, VmBuilder::VmState::kVmUnknown);
assert(vm_info != nullptr);
return std::move(*vm_info);
}

Expand All @@ -89,8 +94,12 @@ bool Client::Notify(CivMsgType t) {
(kCivServerObjData)
();

if (!data) {
return false;
}
data->type = t;
strncpy(data->payload, client_shm_name_.c_str(), sizeof(data->payload));
strncpy(data->payload, client_shm_name_.c_str(), sizeof(data->payload) - 1);
data->payload[sizeof(data->payload) - 1] = '\0';

boost::interprocess::scoped_lock<boost::interprocess::interprocess_mutex> lock_cond(sync.first->mutex_cond);
sync.first->cond_s.notify_one();
Expand Down
2 changes: 1 addition & 1 deletion src/services/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Server final {

bool stop_server_ = false;

CivMsgSync *sync_;
CivMsgSync *sync_ = nullptr;

std::vector<std::unique_ptr<VmBuilder>> vmis_;

Expand Down
17 changes: 14 additions & 3 deletions src/utils/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ const char *GetConfigPath(void) {
}

if (sudo_uid) {
euid = atoi(sudo_gid);
euid = atoi(sudo_uid);
setresuid(ruid, euid, suid);
}

civ_config_path = new char[MAX_PATH];
memset(civ_config_path, 0, MAX_PATH);
snprintf(civ_config_path, MAX_PATH, "%s%s", getpwuid(euid)->pw_dir, "/.intel/.civ");

struct passwd pwd;
struct passwd *ppwd = &pwd;
struct passwd *presult = NULL;
char buffer[4096];
ret = getpwuid_r(euid, ppwd, buffer, sizeof(buffer), &presult);
if (ret != 0 || presult == NULL)
return NULL;

snprintf(civ_config_path, MAX_PATH, "%s%s", pwd.pw_dir, "/.intel/.civ");
if (!boost::filesystem::exists(civ_config_path)) {
if (!boost::filesystem::create_directories(civ_config_path)) {
delete[] civ_config_path;
Expand Down Expand Up @@ -106,8 +115,10 @@ int Daemonize(void) {
close(STDERR_FILENO);

int fd = open("/dev/null", O_RDWR);
if (fd != STDIN_FILENO)
if (fd != STDIN_FILENO) {
close(fd);
return -1;
}
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO)
return -1;
if (dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
Expand Down
4 changes: 2 additions & 2 deletions src/vm_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static bool ListGuest(void) {
}
auto vm_list = c.GetGuestLists();
std::cout << "=====================" << std::endl;
for (auto it : vm_list) {
for (auto& it : vm_list) {
std::cout << it << std::endl;
}
return true;
Expand All @@ -70,7 +70,7 @@ static int GetGuestState(std::string name) {
LOG(error) << "List guest: " << " Failed!";
}
auto vm_list = c.GetGuestLists();
for (auto it : vm_list) {
for (auto& it : vm_list) {
std::vector<std::string> sp;
boost::split(sp, it, boost::is_any_of(":"));
if (sp.size() != 2)
Expand Down