Skip to content

Commit

Permalink
Fixing for a potential error with stringstream.str().c_str()
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Mar 10, 2021
1 parent 79af25e commit b3c9767
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
7 changes: 6 additions & 1 deletion lib/gr_blocks/nonstop_wavfile_sink_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ int nonstop_wavfile_sink_impl::work(int noutput_items, gr_vector_const_void_sta

gr::thread::scoped_lock guard(d_mutex); // hold mutex for duration of this

if (d_first_work ) // drop output on the floor
// if we do not have a valid current_call, dropp everything on the floor.
if (d_current_call == NULL) {
return noutput_items;
}

if (d_first_work )
{
if (d_fp) {
BOOST_LOG_TRIVIAL(error) << "Weird - trying to open a file, but already have a FP";
Expand Down
23 changes: 13 additions & 10 deletions trunk-recorder/call.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,35 @@ void Call::create_filename() {

std::stringstream path_stream;

// Found some good advice on Streams and Strings here: https://blog.sensecodons.com/2013/04/dont-let-stdstringstreamstrcstr-happen.html
path_stream << this->config.capture_dir << "/" << sys->get_short_name() << "/" << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday;
strcpy(path, path_stream.str().c_str());
boost::filesystem::create_directories(path_stream.str());
std::string path_string = path_stream.str();
strcpy(path, path_string.c_str());
boost::filesystem::create_directories(path_string);

int nchars;
nchars = snprintf(filename, 255, "%s/%ld-%ld_%.0f.wav", path_stream.str().c_str(), talkgroup, start_time, curr_freq);
nchars = snprintf(filename, 255, "%s/%ld-%ld_%.0f.wav", path_string.c_str(), talkgroup, start_time, curr_freq);

if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}
nchars = snprintf(status_filename, 255, "%s/%ld-%ld_%.0f.json", path_stream.str().c_str(), talkgroup, start_time, curr_freq);
nchars = snprintf(status_filename, 255, "%s/%ld-%ld_%.0f.json", path_string.c_str(), talkgroup, start_time, curr_freq);

if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}

nchars = snprintf(converted_filename, 255, "%s/%ld-%ld_%.0f.m4a", path_stream.str().c_str(), talkgroup, start_time, curr_freq);
nchars = snprintf(converted_filename, 255, "%s/%ld-%ld_%.0f.m4a", path_string.c_str(), talkgroup, start_time, curr_freq);
if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}

nchars = snprintf(debug_filename, 255, "%s/%ld-%ld_%.0f.debug", path_stream.str().c_str(), talkgroup, start_time, curr_freq);
nchars = snprintf(debug_filename, 255, "%s/%ld-%ld_%.0f.debug", path_string.c_str(), talkgroup, start_time, curr_freq);
if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}

nchars = snprintf(sigmf_filename, 255, "%s/%ld-%ld_%.0f.raw", path_stream.str().c_str(), talkgroup, start_time, curr_freq);
nchars = snprintf(sigmf_filename, 255, "%s/%ld-%ld_%.0f.raw", path_string.c_str(), talkgroup, start_time, curr_freq);
if (nchars >= 255) {
BOOST_LOG_TRIVIAL(error) << "Call: Path longer than 255 charecters";
}
Expand Down Expand Up @@ -111,6 +113,7 @@ void Call::restart_call() {

void Call::end_call() {
std::stringstream shell_command;
std::string shell_command_string;
stop_time = time(NULL);

if (state == recording) {
Expand Down Expand Up @@ -164,17 +167,17 @@ void Call::end_call() {
shell_command << "./" << sys->get_upload_script() << " " << this->get_filename() << " &";
}
this->get_recorder()->stop();

shell_command_string = shell_command.str();
if (this->get_recorder()->get_current_length() > sys->get_min_duration()) {
if (this->config.upload_server != "" || this->config.bcfy_calls_server != "") {
send_call(this, sys, config);
}

if (sys->get_upload_script().length() != 0) {
BOOST_LOG_TRIVIAL(info) << "Running upload script: " << shell_command.str();
BOOST_LOG_TRIVIAL(info) << "Running upload script: " << shell_command_string;
signal(SIGCHLD, SIG_IGN);
//int rc = system(shell_command.str().c_str());
system(shell_command.str().c_str());
system(shell_command_string.c_str());
}

// These files may have already been deleted by upload_call_thread() so only do deletion here if that wasn't called
Expand Down
16 changes: 12 additions & 4 deletions trunk-recorder/uploaders/openmhz_uploader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

int OpenmhzUploader::upload(struct call_data_t *call) {
std::ostringstream freq;
std::string freq_string;
freq << std::fixed << std::setprecision(0);
freq << call->freq;

std::ostringstream call_length;
std::string call_length_string;
call_length << std::fixed << std::setprecision(0);
call_length << call->length;

std::ostringstream source_list;
std::string source_list_string;
source_list << std::fixed << std::setprecision(2);
source_list << "[";

Expand All @@ -31,6 +34,7 @@ int OpenmhzUploader::upload(struct call_data_t *call) {
}

std::ostringstream freq_list;
std::string freq_list_string;
freq_list << std::fixed << std::setprecision(2);
freq_list << "[";

Expand All @@ -55,6 +59,10 @@ int OpenmhzUploader::upload(struct call_data_t *call) {
CURLM *multi_handle;
int still_running = 0;
std::string response_buffer;
freq_string = freq.str();
freq_list_string = freq_list.str();
source_list_string = source_list.str();
call_length_string = call_length.str();

struct curl_httppost *formpost = NULL;
struct curl_httppost *lastptr = NULL;
Expand All @@ -72,7 +80,7 @@ int OpenmhzUploader::upload(struct call_data_t *call) {
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "freq",
CURLFORM_COPYCONTENTS, freq.str().c_str(),
CURLFORM_COPYCONTENTS, freq_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
Expand All @@ -90,7 +98,7 @@ int OpenmhzUploader::upload(struct call_data_t *call) {
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "call_length",
CURLFORM_COPYCONTENTS, call_length.str().c_str(),
CURLFORM_COPYCONTENTS, call_length_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
Expand All @@ -114,13 +122,13 @@ int OpenmhzUploader::upload(struct call_data_t *call) {
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "source_list",
CURLFORM_COPYCONTENTS, source_list.str().c_str(),
CURLFORM_COPYCONTENTS, source_list_string.c_str(),
CURLFORM_END);

curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "freq_list",
CURLFORM_COPYCONTENTS, freq_list.str().c_str(),
CURLFORM_COPYCONTENTS, freq_list_string.c_str(),
CURLFORM_END);

curl = curl_easy_init();
Expand Down

0 comments on commit b3c9767

Please sign in to comment.