client: use snprintf() instead of sprintf() in a few places

... none of which was a possible overrun, but doesn't hurt to check.
This commit is contained in:
David Anderson 2017-08-15 17:06:29 -07:00
parent 8e7857623e
commit b355a13f8d
4 changed files with 12 additions and 6 deletions

View File

@ -492,7 +492,7 @@ void ACTIVE_TASK::handle_exited_app(int stat) {
default:
char szError[1024];
set_task_state(PROCESS_EXITED, "handle_exited_app");
sprintf(err_msg,
snprintf(err_msg, sizeof(err_msg),
"%s - exit code %d (0x%x)",
windows_format_error_string(exit_code, szError, sizeof(szError)),
exit_code, exit_code
@ -529,7 +529,7 @@ void ACTIVE_TASK::handle_exited_app(int stat) {
}
if (result->exit_status) {
set_task_state(PROCESS_EXITED, "handle_exited_app");
sprintf(err_msg,
snprintf(err_msg, sizeof(err_msg),
"process exited with code %d (0x%x, %d)",
result->exit_status, result->exit_status,
(-1<<8)|result->exit_status
@ -568,7 +568,9 @@ void ACTIVE_TASK::handle_exited_app(int stat) {
result->exit_status = stat;
set_task_state(PROCESS_WAS_SIGNALED, "handle_exited_app");
signal = got_signal;
sprintf(err_msg, "process got signal %d", signal);
snprintf(err_msg, sizeof(err_msg),
"process got signal %d", signal
);
gstate.report_result_error(*result, err_msg);
}
} else {

View File

@ -1167,7 +1167,7 @@ error:
//
gstate.input_files_available(result, true);
char err_msg[4096];
sprintf(err_msg, "couldn't start app: %s", buf);
snprintf(err_msg, sizeof(err_msg), "couldn't start app: %s", buf);
gstate.report_result_error(*result, err_msg);
if (log_flags.task_debug) {
msg_printf(wup->project, MSG_INFO,

View File

@ -160,7 +160,9 @@ int ASYNC_COPY::copy_chunk() {
void ASYNC_COPY::error(int retval) {
char err_msg[4096];
atp->set_task_state(PROCESS_COULDNT_START, "ASYNC_COPY::error");
sprintf(err_msg, "Couldn't copy file: %s", boincerror(retval));
snprintf(err_msg, sizeof(err_msg),
"Couldn't copy file: %s", boincerror(retval)
);
gstate.report_result_error(*(atp->result), err_msg);
gstate.request_schedule_cpus("start failed");
}

View File

@ -1443,7 +1443,9 @@ bool CLIENT_STATE::enforce_run_list(vector<RESULT*>& run_list) {
}
if (retval) {
char err_msg[4096];
sprintf(err_msg, "Couldn't start or resume: %d", retval);
snprintf(err_msg, sizeof(err_msg),
"Couldn't start or resume: %d", retval
);
report_result_error(*(atp->result), err_msg);
request_schedule_cpus("start failed");
continue;