Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
Remove null bytes for libdbi.
Browse files Browse the repository at this point in the history
  • Loading branch information
zit-hb committed Mar 6, 2016
1 parent f86916a commit 04699d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions include/database.h
Expand Up @@ -248,6 +248,11 @@ namespace swd {
* @brief The mutex for database access.
*/
boost::mutex dbi_mutex_;

/**
* @brief Remove nullbytes for libdbi.
*/
std::string remove_null(std::string target);
};

/**
Expand Down
19 changes: 12 additions & 7 deletions src/database.cpp
Expand Up @@ -311,13 +311,13 @@ int swd::database::save_request(const int& profile_id, const std::string& caller

boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

char *caller_esc = strdup(caller.c_str());
char *caller_esc = strdup(remove_null(caller).c_str());
dbi_conn_quote_string(conn_, &caller_esc);

char *resource_esc = strdup(resource.c_str());
char *resource_esc = strdup(remove_null(resource).c_str());
dbi_conn_quote_string(conn_, &resource_esc);

char *client_ip_esc = strdup(client_ip.c_str());
char *client_ip_esc = strdup(remove_null(client_ip).c_str());
dbi_conn_quote_string(conn_, &client_ip_esc);

dbi_result res = dbi_conn_queryf(conn_, "INSERT INTO requests (profile_id, "
Expand Down Expand Up @@ -347,10 +347,10 @@ int swd::database::save_parameter(const int& request_id, const std::string& path

boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

char *path_esc = strdup(path.c_str());
char *path_esc = strdup(remove_null(path).c_str());
dbi_conn_quote_string(conn_, &path_esc);

char *value_esc = strdup(value.c_str());
char *value_esc = strdup(remove_null(value).c_str());
dbi_conn_quote_string(conn_, &value_esc);

dbi_result res = dbi_conn_queryf(conn_, "INSERT INTO parameters "
Expand Down Expand Up @@ -379,10 +379,10 @@ int swd::database::save_hash(const int& request_id, const std::string& algorithm

boost::unique_lock<boost::mutex> scoped_lock(dbi_mutex_);

char *algorithm_esc = strdup(algorithm.c_str());
char *algorithm_esc = strdup(remove_null(algorithm).c_str());
dbi_conn_quote_string(conn_, &algorithm_esc);

char *digest_esc = strdup(digest.c_str());
char *digest_esc = strdup(remove_null(digest).c_str());
dbi_conn_quote_string(conn_, &digest_esc);

dbi_result res = dbi_conn_queryf(conn_, "INSERT INTO hashes (request_id, "
Expand Down Expand Up @@ -490,3 +490,8 @@ void swd::database::set_cache_outdated(const int& profile_id,
throw swd::exceptions::database_exception("Can't execute cache_outdated query");
}
}

std::string swd::database::remove_null(std::string target) {
std::replace(target.begin(), target.end(), '\0', ' ');
return target;
}

0 comments on commit 04699d8

Please sign in to comment.