From 2cc9a0b6c4da8b4f841902b07152069b17fd9a19 Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Thu, 18 Feb 2016 00:59:13 -0500 Subject: [PATCH] client: Cleanup low hanging fruit with regards to cleaning up sprintf. Use snprintf instead. --- client/acct_mgr.cpp | 6 ++++- client/app.cpp | 17 +++++++++--- client/app_start.cpp | 49 +++++++++++++++++++---------------- client/async_file.cpp | 4 +++ client/client_state.cpp | 14 ++++++---- client/client_types.cpp | 10 ++++--- client/cs_account.cpp | 10 +++---- client/cs_benchmark.cpp | 8 ++++-- client/cs_files.cpp | 10 ++++--- client/cs_notice.cpp | 44 +++++++++++++++++-------------- client/cs_notice.h | 4 +-- client/cs_scheduler.cpp | 14 ++++++---- client/cs_statefile.cpp | 6 ++++- client/cs_trickle.cpp | 21 +++++++++------ client/file_names.cpp | 8 +++--- client/file_names.h | 4 +-- client/file_xfer.cpp | 8 ++++-- client/gpu_amd.cpp | 14 +++++----- client/gui_rpc_server_ops.cpp | 11 +++++--- client/hostinfo_network.cpp | 12 ++++++--- client/http_curl.cpp | 30 ++++++++++++++------- client/log_flags.cpp | 5 ++-- client/project.cpp | 12 ++++++--- client/result.cpp | 19 +++++++++++--- client/rr_sim.cpp | 15 +++++++---- client/sandbox.cpp | 12 ++++++--- client/scheduler_op.cpp | 12 ++++++--- client/sysmon_win.cpp | 6 ++++- client/time_stats.cpp | 12 +++++++-- client/work_fetch.cpp | 34 +++++++++++++++++------- 30 files changed, 282 insertions(+), 149 deletions(-) diff --git a/client/acct_mgr.cpp b/client/acct_mgr.cpp index 280d5fed3b..c7db2d8da3 100644 --- a/client/acct_mgr.cpp +++ b/client/acct_mgr.cpp @@ -24,6 +24,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "crypt.h" #include "error_numbers.h" #include "parse.h" @@ -201,7 +205,7 @@ int ACCT_MGR_OP::do_rpc( gstate.net_stats.write(mf); fprintf(f, "\n"); fclose(f); - sprintf(buf, "%srpc.php", url); + snprintf(buf, sizeof(buf), "%srpc.php", url); retval = gui_http->do_rpc_post( this, buf, ACCT_MGR_REQUEST_FILENAME, ACCT_MGR_REPLY_FILENAME, true ); diff --git a/client/app.cpp b/client/app.cpp index 4e72df1095..712e8fdbbf 100644 --- a/client/app.cpp +++ b/client/app.cpp @@ -52,6 +52,9 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif #include "error_numbers.h" #include "filesys.h" @@ -517,8 +520,11 @@ int ACTIVE_TASK::move_trickle_file() { char new_path[MAXPATHLEN], old_path[MAXPATHLEN]; int retval; - sprintf(old_path, "%s/trickle_up.xml", slot_dir); - sprintf(new_path, + snprintf(old_path, sizeof(old_path), + "%s/trickle_up.xml", + slot_dir + ); + snprintf(new_path, sizeof(new_path), "%s/trickle_up_%s_%d.xml", result->project->project_dir(), result->name, (int)time(0) ); @@ -1060,7 +1066,7 @@ int ACTIVE_TASK::handle_upload_files() { "Can't find uploadable file %s", p ); } - sprintf(path, "%s/%s", slot_dir, buf); + snprintf(path, sizeof(path), "%s/%s", slot_dir, buf); delete_project_owned_file(path, true); // delete the link file } } @@ -1095,7 +1101,10 @@ void ACTIVE_TASK_SET::network_available() { void ACTIVE_TASK::upload_notify_app(const FILE_INFO* fip, const FILE_REF* frp) { char path[MAXPATHLEN]; - sprintf(path, "%s/%s%s", slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name); + snprintf(path, sizeof(path), + "%s/%s%s", + slot_dir, UPLOAD_FILE_STATUS_PREFIX, frp->open_name + ); FILE* f = boinc_fopen(path, "w"); if (!f) return; fprintf(f, "%d\n", fip->status); diff --git a/client/app_start.cpp b/client/app_start.cpp index 3e03b0557b..20e9c9bf00 100644 --- a/client/app_start.cpp +++ b/client/app_start.cpp @@ -351,7 +351,7 @@ static int create_dirs_for_logical_name( static void prepend_prefix(APP_VERSION* avp, char* in, char* out, int len) { if (strlen(avp->file_prefix)) { - sprintf(out, "%s/%s", avp->file_prefix, in); + snprintf(out, len, "%s/%s", avp->file_prefix, in); } else { strlcpy(out, in, len); } @@ -395,12 +395,12 @@ int ACTIVE_TASK::setup_file( } retval = create_dirs_for_logical_name(open_name, slot_dir); if (retval) return retval; - sprintf(link_path, "%s/%s", slot_dir, open_name); + snprintf(link_path, sizeof(link_path), "%s/%s", slot_dir, open_name); } else { - sprintf(link_path, "%s/%s", slot_dir, fip->name); + snprintf(link_path, sizeof(link_path), "%s/%s", slot_dir, fip->name); } - sprintf(rel_file_path, "../../%s", file_path ); + snprintf(rel_file_path, sizeof(rel_file_path), "../../%s", file_path ); if (boinc_file_exists(link_path)) { return 0; @@ -476,7 +476,7 @@ int ACTIVE_TASK::copy_output_files() { prepend_prefix( app_version, fref.open_name, open_name, sizeof(open_name) ); - sprintf(slotfile, "%s/%s", slot_dir, open_name); + snprintf(slotfile, sizeof(slotfile), "%s/%s", slot_dir, open_name); get_pathname(fip, projfile, sizeof(projfile)); int retval = boinc_rename(slotfile, projfile); // the rename fails if the output file isn't there. @@ -606,7 +606,7 @@ int ACTIVE_TASK::start(bool test) { if (!app_client_shm.shm) { retval = get_shmem_seg_name(); if (retval) { - sprintf(buf, + snprintf(buf, sizeof(buf), "Can't get shared memory segment name: %s", boincerror(retval) ); @@ -620,7 +620,7 @@ int ACTIVE_TASK::start(bool test) { init_app_init_data(aid); retval = write_app_init_file(aid); if (retval) { - sprintf(buf, "Can't write init file: %s", boincerror(retval)); + snprintf(buf, sizeof(buf), "Can't write init file: %s", boincerror(retval)); goto error; } @@ -638,12 +638,12 @@ int ACTIVE_TASK::start(bool test) { get_pathname(fip, file_path, sizeof(file_path)); if (fref.main_program) { if (is_image_file(fip->name)) { - sprintf(buf, "Main program %s is an image file", fip->name); + snprintf(buf, sizeof(buf), "Main program %s is an image file", fip->name); retval = ERR_NO_SIGNATURE; goto error; } if (!fip->executable && !wup->project->anonymous_platform) { - sprintf(buf, "Main program %s is not executable", fip->name); + snprintf(buf, sizeof(buf), "Main program %s is not executable", fip->name); retval = ERR_NO_SIGNATURE; goto error; } @@ -697,7 +697,7 @@ int ACTIVE_TASK::start(bool test) { // remove temporary exit file from last run // - sprintf(file_path, "%s/%s", slot_dir, TEMPORARY_EXIT_FILE); + snprintf(file_path, sizeof(file_path), "%s/%s", slot_dir, TEMPORARY_EXIT_FILE); delete_project_owned_file(file_path, true); if (cc_config.exit_before_start) { @@ -732,7 +732,8 @@ int ACTIVE_TASK::start(bool test) { return 0; } - sprintf(cmdline, "%s %s %s", + snprintf(cmdline, sizeof(cmdline), + "%s %s %s", exec_path, wup->command_line.c_str(), app_version->cmdline ); if (!app_version->api_version_at_least(7, 5)) { @@ -825,7 +826,7 @@ int ACTIVE_TASK::start(bool test) { } if (!success) { - sprintf(buf, "CreateProcess() failed - %s", error_msg); + snprintf(buf, sizeof(buf), "CreateProcess() failed - %s", error_msg); if (last_error == ERROR_NOT_ENOUGH_MEMORY) { // if CreateProcess() failed because system is low on memory, @@ -884,10 +885,10 @@ int ACTIVE_TASK::start(bool test) { if (log_flags.task_debug) { debug_print_argv(argv); } - sprintf(buf, "../../%s", exec_path ); + snprintf(buf, sizeof(buf), "../../%s", exec_path ); pid = spawnv(P_NOWAIT, buf, argv); if (pid == -1) { - sprintf(buf, "Process creation failed: %s\n", boincerror(retval)); + snprintf(buf, sizeof(buf), "Process creation failed: %s\n", boincerror(retval)); chdir(current_dir); retval = ERR_EXEC; goto error; @@ -916,11 +917,12 @@ int ACTIVE_TASK::start(bool test) { char current_dir[1024]; if (getcwd(current_dir, sizeof(current_dir)) == NULL) { - sprintf(buf, "Can't get cwd"); + snprintf(buf, sizeof(buf), "Can't get cwd"); goto error; } - sprintf(cmdline, "%s %s", + snprintf(cmdline, sizeof(cmdline), + "%s %s", wup->command_line.c_str(), app_version->cmdline ); @@ -940,7 +942,7 @@ int ACTIVE_TASK::start(bool test) { if (app_version->api_version_at_least(6, 0)) { #endif // Use mmap() shared memory - sprintf(buf, "%s/%s", slot_dir, MMAPPED_FILE_NAME); + snprintf(buf, sizeof(buf), "%s/%s", slot_dir, MMAPPED_FILE_NAME); if (g_use_sandbox) { if (!boinc_file_exists(buf)) { int fd = open(buf, O_RDWR | O_CREAT, 0660); @@ -988,7 +990,7 @@ int ACTIVE_TASK::start(bool test) { } pid = fork(); if (pid == -1) { - sprintf(buf, "fork() failed: %s", strerror(errno)); + snprintf(buf, sizeof(buf), "fork() failed: %s", strerror(errno)); retval = ERR_FORK; goto error; } @@ -1013,9 +1015,9 @@ int ACTIVE_TASK::start(bool test) { // char libpath[8192]; char newlibs[256]; - sprintf(newlibs, "../../%s:.:../..", wup->project->project_dir()); + snprintf(newlibs, sizeof(newlibs), "../../%s:.:../..", wup->project->project_dir()); #ifdef __APPLE__ - strcat(newlibs, ":/usr/local/cuda/lib/"); + strlcat(newlibs, sizeof(newlibs), ":/usr/local/cuda/lib/"); #endif char* p = getenv("LD_LIBRARY_PATH"); if (p) { @@ -1106,11 +1108,12 @@ int ACTIVE_TASK::start(bool test) { if (test) { strcpy(buf, exec_path); } else { - sprintf(buf, "../../%s", exec_path); + snprintf(buf, sizeof(buf), "../../%s", exec_path); } if (g_use_sandbox) { char switcher_path[MAXPATHLEN]; - sprintf(switcher_path, "../../%s/%s", + snprintf(switcher_path, sizeof(switcher_path), + "../../%s/%s", SWITCHER_DIR, SWITCHER_FILE_NAME ); argv[0] = const_cast(SWITCHER_FILE_NAME); @@ -1218,7 +1221,7 @@ int ACTIVE_TASK::resume_or_start(bool first_time) { char buf[256]; safe_strcpy(buf, ""); if (strlen(app_version->plan_class)) { - sprintf(buf, " (%s)", app_version->plan_class); + snprintf(buf, sizeof(buf), " (%s)", app_version->plan_class); } msg_printf(result->project, MSG_INFO, "[cpu_sched] %s task %s using %s version %d%s in slot %d", diff --git a/client/async_file.cpp b/client/async_file.cpp index 737cbbf2ac..b19660e862 100644 --- a/client/async_file.cpp +++ b/client/async_file.cpp @@ -21,6 +21,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "crypt.h" #include "error_numbers.h" #include "filesys.h" diff --git a/client/client_state.cpp b/client/client_state.cpp index 410771e953..7b3a65f13c 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -36,6 +36,10 @@ #endif #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #ifdef __EMX__ #define INCL_DOS #include @@ -412,7 +416,7 @@ static void set_client_priority() { #endif #ifdef __linux__ char buf[1024]; - sprintf(buf, "ionice -c 3 -p %d", getpid()); + snprintf(buf, sizeof(buf), "ionice -c 3 -p %d", getpid()); system(buf); #endif } @@ -1003,14 +1007,14 @@ bool CLIENT_STATE::poll_slow_events() { if (!old_network_suspend_reason) { char buf[256]; if (network_suspended) { - sprintf(buf, + snprintf(buf, sizeof(buf), "Suspending network activity - %s", suspend_reason_string(network_suspend_reason) ); request_schedule_cpus("network suspended"); // in case any "needs_network" jobs are running } else { - sprintf(buf, + snprintf(buf, sizeof(buf), "Suspending file transfers - %s", suspend_reason_string(network_suspend_reason) ); @@ -2080,7 +2084,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) { // delete statistics file // - get_statistics_filename(project->master_url, path); + get_statistics_filename(project->master_url, path, sizeof(path)); retval = boinc_delete_file(path); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, @@ -2090,7 +2094,7 @@ int CLIENT_STATE::detach_project(PROJECT* project) { // delete account file // - get_account_filename(project->master_url, path); + get_account_filename(project->master_url, path, sizeof(path)); retval = boinc_delete_file(path); if (retval) { msg_printf(project, MSG_INTERNAL_ERROR, diff --git a/client/client_types.cpp b/client/client_types.cpp index 0e5764e8c7..063d224fdf 100644 --- a/client/client_types.cpp +++ b/client/client_types.cpp @@ -37,6 +37,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "filesys.h" #include "log_flags.h" @@ -598,7 +602,7 @@ int FILE_INFO::merge_info(FILE_INFO& new_info) { if (max_nbytes <= 0 && new_info.max_nbytes) { max_nbytes = new_info.max_nbytes; - sprintf(buf, " %.0f\n", new_info.max_nbytes); + snprintf(buf, sizeof(buf), " %.0f\n", new_info.max_nbytes); } // replace existing URLs with new ones @@ -668,7 +672,7 @@ bool FILE_INFO::had_failure(int& failnum) { void FILE_INFO::failure_message(string& s) { char buf[1024]; - sprintf(buf, + snprintf(buf, sizeof(buf), "\n" " %s\n" " %d (%s)\n", @@ -677,7 +681,7 @@ void FILE_INFO::failure_message(string& s) { ); s = buf; if (error_msg.size()) { - sprintf(buf, + snprintf(buf, sizeof(buf), " %s\n", error_msg.c_str() ); diff --git a/client/cs_account.cpp b/client/cs_account.cpp index a75726de28..85fe08bb78 100644 --- a/client/cs_account.cpp +++ b/client/cs_account.cpp @@ -59,7 +59,7 @@ int PROJECT::write_account_file() { FILE* f; int retval; - get_account_filename(master_url, path); + get_account_filename(master_url, path, sizeof(path)); f = boinc_fopen(TEMP_ACCT_FILE_NAME, "w"); if (!f) return ERR_FOPEN; @@ -202,7 +202,7 @@ int PROJECT::parse_account_file_venue() { bool in_right_venue = false, btemp; double dtemp; - get_account_filename(master_url, path); + get_account_filename(master_url, path, sizeof(path)); FILE* in = boinc_fopen(path, "r"); if (!in) return ERR_FOPEN; @@ -291,7 +291,7 @@ int PROJECT::parse_account_file() { int retval; FILE* f; - get_account_filename(master_url, path); + get_account_filename(master_url, path, sizeof(path)); f = boinc_fopen(path, "r"); if (!f) return ERR_FOPEN; retval = parse_account(f); @@ -464,7 +464,7 @@ int PROJECT::write_statistics_file() { FILE* f; int retval; - get_statistics_filename(master_url, path); + get_statistics_filename(master_url, path, sizeof(path)); f = boinc_fopen(TEMP_STATS_FILE_NAME, "w"); if (!f) return ERR_FOPEN; fprintf(f, @@ -551,7 +551,7 @@ int CLIENT_STATE::add_project( return retval; } - get_account_filename(canonical_master_url, path); + get_account_filename(canonical_master_url, path, sizeof(path)); f = boinc_fopen(path, "r"); if (!f) { delete project; diff --git a/client/cs_benchmark.cpp b/client/cs_benchmark.cpp index 85a1aa62c4..f185df4e6d 100644 --- a/client/cs_benchmark.cpp +++ b/client/cs_benchmark.cpp @@ -54,6 +54,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "file_names.h" #include "filesys.h" @@ -190,7 +194,7 @@ int cpu_benchmarks(BENCHMARK_DESC* bdp) { #endif if (retval) { bdp->error = true; - sprintf(bdp->error_str, "FP benchmark ran only %f sec; ignoring", fp_time); + snprintf(bdp->error_str, sizeof(bdp->error_str), "FP benchmark ran only %f sec; ignoring", fp_time); return 0; } #ifdef _WIN32 @@ -204,7 +208,7 @@ int cpu_benchmarks(BENCHMARK_DESC* bdp) { retval = dhrystone(vax_mips, int_loops, int_time, MIN_CPU_TIME); if (retval) { bdp->error = true; - sprintf(bdp->error_str, "Integer benchmark ran only %f sec; ignoring", int_time); + snprintf(bdp->error_str, sizeof(bdp->error_str), "Integer benchmark ran only %f sec; ignoring", int_time); return 0; } host_info.p_iops = vax_mips*1e6; diff --git a/client/cs_files.cpp b/client/cs_files.cpp index f8ce4e7f6a..e757238b38 100644 --- a/client/cs_files.cpp +++ b/client/cs_files.cpp @@ -30,6 +30,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "md5_file.h" #include "crypt.h" #include "str_replace.h" @@ -188,7 +192,7 @@ int FILE_INFO::verify_file( // if (download_gzipped && !boinc_file_exists(pathname)) { char gzpath[MAXPATHLEN]; - sprintf(gzpath, "%s.gz", pathname); + snprintf(gzpath, sizeof(gzpath), "%s.gz", pathname); if (boinc_file_exists(gzpath) ) { if (allow_async && nbytes > ASYNC_FILE_THRESHOLD) { ASYNC_VERIFY* avp = new ASYNC_VERIFY; @@ -414,8 +418,8 @@ bool CLIENT_STATE::create_and_delete_pers_file_xfers() { if (fip->download_gzipped) { char path[MAXPATHLEN], from_path[MAXPATHLEN], to_path[MAXPATHLEN]; get_pathname(fip, path, sizeof(path)); - sprintf(from_path, "%s.gzt", path); - sprintf(to_path, "%s.gz", path); + snprintf(from_path, sizeof(from_path), "%s.gzt", path); + snprintf(to_path, sizeof(to_path), "%s.gz", path); boinc_rename(from_path, to_path); } diff --git a/client/cs_notice.cpp b/client/cs_notice.cpp index 73ca3f189f..6a34950e35 100644 --- a/client/cs_notice.cpp +++ b/client/cs_notice.cpp @@ -24,6 +24,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "parse.h" #include "url.h" #include "filesys.h" @@ -52,10 +56,10 @@ static bool cmp(NOTICE n1, NOTICE n2) { return (strcmp(n1.guid, n2.guid) > 0); } -static void project_feed_list_file_name(PROJ_AM* p, char* buf) { +static void project_feed_list_file_name(PROJ_AM* p, char* buf, int len) { char url[256]; escape_project_url(p->master_url, url); - sprintf(buf, "notices/feeds_%s.xml", url); + snprintf(buf, len, "notices/feeds_%s.xml", url); } // parse feed descs from scheduler reply or feed list file @@ -95,7 +99,7 @@ static void write_rss_feed_descs(MIOFILE& fout, vector& feeds) { static void write_project_feed_list(PROJ_AM* p) { char buf[256]; - project_feed_list_file_name(p, buf); + project_feed_list_file_name(p, buf, sizeof(buf)); FILE* f = fopen(buf, "w"); if (!f) return; MIOFILE fout; @@ -496,7 +500,7 @@ void NOTICES::write_archive(RSS_FEED* rfp) { char path[MAXPATHLEN]; if (rfp) { - rfp->archive_file_name(path); + rfp->archive_file_name(path, sizeof(path)); } else { safe_strcpy(path, NOTICES_DIR"/archive.xml"); } @@ -609,16 +613,16 @@ void NOTICES::write(int seqno, GUI_RPC_CONN& grc, bool public_only) { ///////////// RSS_FEED //////////////// -void RSS_FEED::feed_file_name(char* path) { +void RSS_FEED::feed_file_name(char* path, int len) { char buf[256]; escape_project_url(url_base, buf); - sprintf(path, NOTICES_DIR"/%s.xml", buf); + snprintf(path, len, NOTICES_DIR"/%s.xml", buf); } -void RSS_FEED::archive_file_name(char* path) { +void RSS_FEED::archive_file_name(char* path, int len) { char buf[256]; escape_project_url(url_base, buf); - sprintf(path, NOTICES_DIR"/archive_%s.xml", buf); + snprintf(path, len, NOTICES_DIR"/archive_%s.xml", buf); } // read and parse the contents of the archive file; @@ -626,7 +630,7 @@ void RSS_FEED::archive_file_name(char* path) { // int RSS_FEED::read_archive_file() { char path[MAXPATHLEN]; - archive_file_name(path); + archive_file_name(path, sizeof(path)); return notices.read_archive_file(path, this); } @@ -752,9 +756,9 @@ int RSS_FEED::parse_items(XML_PARSER& xp, int& nitems) { void RSS_FEED::delete_files() { char path[MAXPATHLEN]; - feed_file_name(path); + feed_file_name(path, sizeof(path)); boinc_delete_file(path); - archive_file_name(path); + archive_file_name(path, sizeof(path)); boinc_delete_file(path); } @@ -770,14 +774,14 @@ RSS_FEED_OP::RSS_FEED_OP() { // bool RSS_FEED_OP::poll() { unsigned int i; + char file_name[256]; if (gstate.gui_http.is_busy()) return false; if (gstate.network_suspended) return false; for (i=0; i rf.next_poll_time) { rf.next_poll_time = gstate.now + rf.poll_interval; - char filename[256]; - rf.feed_file_name(filename); + rf.feed_file_name(file_name, sizeof(file_name)); rfp = &rf; if (log_flags.notice_debug) { msg_printf(0, MSG_INFO, @@ -786,7 +790,7 @@ bool RSS_FEED_OP::poll() { } char url[1024]; safe_strcpy(url, rf.url); - gstate.gui_http.do_rpc(this, url, filename, true); + gstate.gui_http.do_rpc(this, url, file_name, true); break; } } @@ -796,7 +800,7 @@ bool RSS_FEED_OP::poll() { // handle a completed RSS feed fetch // void RSS_FEED_OP::handle_reply(int http_op_retval) { - char filename[256]; + char file_name[256]; int nitems; if (!rfp) return; // op was canceled @@ -816,11 +820,11 @@ void RSS_FEED_OP::handle_reply(int http_op_retval) { ); } - rfp->feed_file_name(filename); - FILE* f = fopen(filename, "r"); + rfp->feed_file_name(file_name, sizeof(file_name)); + FILE* f = fopen(file_name, "r"); if (!f) { msg_printf(0, MSG_INTERNAL_ERROR, - "RSS feed file '%s' not found", filename + "RSS feed file '%s' not found", file_name ); return; } @@ -847,7 +851,7 @@ static void init_proj_am(PROJ_AM* p) { MIOFILE fin; char path[MAXPATHLEN]; - project_feed_list_file_name(p, path); + project_feed_list_file_name(p, path, sizeof(path)); f = fopen(path, "r"); if (f) { fin.init_file(f); @@ -987,6 +991,6 @@ void RSS_FEEDS::write_feed_list() { void delete_project_notice_files(PROJECT* p) { char path[MAXPATHLEN]; - project_feed_list_file_name(p, path); + project_feed_list_file_name(p, path, sizeof(path)); boinc_delete_file(path); } diff --git a/client/cs_notice.h b/client/cs_notice.h index 8d6384fe06..d6efe054ae 100644 --- a/client/cs_notice.h +++ b/client/cs_notice.h @@ -114,8 +114,8 @@ struct RSS_FEED { void write(MIOFILE&); int parse_desc(XML_PARSER&); int parse_items(XML_PARSER&, int&); - void feed_file_name(char*); - void archive_file_name(char*); + void feed_file_name(char*, int); + void archive_file_name(char*, int); int read_archive_file(); void delete_files(); }; diff --git a/client/cs_scheduler.cpp b/client/cs_scheduler.cpp index 699ff9a35c..3bf6959a4b 100644 --- a/client/cs_scheduler.cpp +++ b/client/cs_scheduler.cpp @@ -34,6 +34,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "crypt.h" #include "error_numbers.h" #include "file_names.h" @@ -334,17 +338,17 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p) { int rt = rp->avp->gpu_usage.rsc_type; if (rt) { if (rt == rsc_index(GPU_TYPE_NVIDIA)) { - sprintf(buf, + snprintf(buf, sizeof(buf), " %f\n", rp->avp->gpu_usage.usage ); } else if (rt == rsc_index(GPU_TYPE_ATI)) { - sprintf(buf, + snprintf(buf, sizeof(buf), " %f\n", rp->avp->gpu_usage.usage ); } else if (rt == rsc_index(GPU_TYPE_INTEL)) { - sprintf(buf, + snprintf(buf, sizeof(buf), " %f\n", rp->avp->gpu_usage.usage ); @@ -573,7 +577,7 @@ int CLIENT_STATE::handle_scheduler_reply( if (log_flags.sched_ops) { if (work_fetch.requested_work()) { - sprintf(buf, ": got %d new tasks", (int)sr.results.size()); + snprintf(buf, sizeof(buf), ": got %d new tasks", (int)sr.results.size()); } else { safe_strcpy(buf, ""); } @@ -1151,7 +1155,7 @@ void CLIENT_STATE::check_project_timeout() { if (p->possibly_backed_off && now > p->min_rpc_time) { p->possibly_backed_off = false; char buf[256]; - sprintf(buf, "Backoff ended for %s", p->get_project_name()); + snprintf(buf, sizeof(buf), "Backoff ended for %s", p->get_project_name()); request_work_fetch(buf); } } diff --git a/client/cs_statefile.cpp b/client/cs_statefile.cpp index ebf74e282d..cf3c4faf31 100644 --- a/client/cs_statefile.cpp +++ b/client/cs_statefile.cpp @@ -24,6 +24,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "filesys.h" #include "md5_file.h" @@ -823,7 +827,7 @@ void CLIENT_STATE::check_anonymous() { for (i=0; iproject_dir(), APP_INFO_FILE_NAME); + snprintf(path, sizeof(path), "%s/%s", p->project_dir(), APP_INFO_FILE_NAME); f = fopen(path, "r"); if (!f) continue; msg_printf(p, MSG_INFO, diff --git a/client/cs_trickle.cpp b/client/cs_trickle.cpp index 8ed9722d5d..e78d4a20b5 100644 --- a/client/cs_trickle.cpp +++ b/client/cs_trickle.cpp @@ -27,6 +27,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "file_names.h" #include "filesys.h" @@ -68,7 +72,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { *p = '_'; t = atoi(p+1); - sprintf(path, "%s/%s", project->project_dir(), fname); + snprintf(path, sizeof(path), "%s/%s", project->project_dir(), fname); retval = read_file_malloc(path, file_contents); if (retval) { if (log_flags.trickle_debug) { @@ -99,7 +103,7 @@ int CLIENT_STATE::read_trickle_files(PROJECT* project, FILE* f) { // append .sent to filename, so we'll know which ones to delete later // if (!ends_with(fname, ".sent")) { - sprintf(newpath, "%s/%s.sent", project->project_dir(), fname); + snprintf(newpath, sizeof(newpath), "%s/%s.sent", project->project_dir(), fname); boinc_rename(path, newpath); } } @@ -120,7 +124,7 @@ int CLIENT_STATE::remove_trickle_files(PROJECT* project) { safe_strcpy(fname, fn.c_str()); if (!starts_with(fname, "trickle_up")) continue; if (!ends_with(fname, ".sent")) continue; - sprintf(path, "%s/%s", project->project_dir(), fname); + snprintf(path, sizeof(path), "%s/%s", project->project_dir(), fname); delete_project_owned_file(path, true); } return 0; @@ -144,7 +148,7 @@ int CLIENT_STATE::handle_trickle_down(PROJECT* project, FILE* in) { if (!rp) return ERR_NULL; ACTIVE_TASK* atp = lookup_active_task_by_result(rp); if (!atp) return ERR_NULL; - sprintf(path, "%s/trickle_down_%d", atp->slot_dir, send_time); + snprintf(path, sizeof(path), "%s/trickle_down_%d", atp->slot_dir, send_time); FILE* f = fopen(path, "w"); if (!f) return ERR_FOPEN; fputs(body.c_str(), f); @@ -177,9 +181,9 @@ bool trickle_up_poll() { } static void trickle_up_request_message( - PROJECT* p, const char* msg, char* result_name, int t, char* buf + PROJECT* p, const char* msg, char* result_name, int t, char* buf, int len ) { - sprintf(buf, + snprintf(buf, len, "\n" " %s\n" " %d\n" @@ -212,9 +216,10 @@ void send_replicated_trickles( PROJECT* p, const char* msg, char* result_name, int now ) { if (!p->trickle_up_ops.size()) return; - char *buf = (char*)malloc(strlen(msg) + 4096); + int trickle_len = strlen(msg) + 4096; + char *buf = (char*)malloc(trickle_len); if (!buf) return; - trickle_up_request_message(p, msg, result_name, now, buf); + trickle_up_request_message(p, msg, result_name, now, buf, trickle_len); for (unsigned int i=0; itrickle_up_ops.size(); i++) { TRICKLE_UP_OP *t = p->trickle_up_ops[i]; if (t->gui_http->is_busy()) { diff --git a/client/file_names.cpp b/client/file_names.cpp index 765716e7ec..4e3b16f426 100644 --- a/client/file_names.cpp +++ b/client/file_names.cpp @@ -261,10 +261,10 @@ void delete_old_slot_dirs() { dir_close(dirp); } -void get_account_filename(char* master_url, char* path) { +void get_account_filename(char* master_url, char* path, int len) { char buf[1024]; escape_project_url(master_url, buf); - sprintf(path, "account_%s.xml", buf); + snprintf(path, len, "account_%s.xml", buf); } static bool bad_account_filename(const char* filename) { @@ -315,10 +315,10 @@ bool is_statistics_file(const char* filename) { return true; } -void get_statistics_filename(char* master_url, char* path) { +void get_statistics_filename(char* master_url, char* path, int len) { char buf[256]; escape_project_url(master_url, buf); - sprintf(path, "statistics_%s.xml", buf); + snprintf(path, len, "statistics_%s.xml", buf); } bool is_image_file(const char* filename) { diff --git a/client/file_names.h b/client/file_names.h index 3bbb8a5dc7..ec27a6dc4e 100644 --- a/client/file_names.h +++ b/client/file_names.h @@ -37,10 +37,10 @@ extern int make_project_dir(PROJECT&); extern int remove_project_dir(PROJECT&); extern int make_slot_dir(int); extern void delete_old_slot_dirs(); -extern void get_account_filename(char* master_url, char* path); +extern void get_account_filename(char* master_url, char* path, int len); extern bool is_account_file(const char*); extern bool is_statistics_file(const char*); -extern void get_statistics_filename(char* master_url, char* path); +extern void get_statistics_filename(char* master_url, char* path, int len); extern bool is_image_file(const char*); extern void get_sched_request_filename(PROJECT&, char*, int len); diff --git a/client/file_xfer.cpp b/client/file_xfer.cpp index 39935ae9cc..08b1a85560 100644 --- a/client/file_xfer.cpp +++ b/client/file_xfer.cpp @@ -23,6 +23,10 @@ #include "config.h" #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "str_replace.h" #include "file_names.h" @@ -106,7 +110,7 @@ int FILE_XFER::init_upload(FILE_INFO& file_info) { } if (file_info.upload_offset < 0) { bytes_xferred = 0; - sprintf(header, + snprintf(header, sizeof(header), "\n" " %d\n" " %d\n" @@ -124,7 +128,7 @@ int FILE_XFER::init_upload(FILE_INFO& file_info) { ); } else { bytes_xferred = file_info.upload_offset; - sprintf(header, + snprintf(header, sizeof(header), "\n" " %d\n" " %d\n" diff --git a/client/gpu_amd.cpp b/client/gpu_amd.cpp index 60be4c91b9..966ddb0241 100644 --- a/client/gpu_amd.cpp +++ b/client/gpu_amd.cpp @@ -160,7 +160,7 @@ void COPROC_ATI::get( void* callib = dlopen("libaticalrt.so", RTLD_NOW); if (!callib) { - sprintf(buf, "ATI: %s", dlerror()); + snprintf(buf, sizeof(buf), "ATI: %s", dlerror()); warnings.push_back(buf); return; } @@ -202,19 +202,19 @@ void COPROC_ATI::get( retval = (*__calInit)(); if (retval != CAL_RESULT_OK) { - sprintf(buf, "calInit() returned %d", retval); + snprintf(buf, sizeof(buf), "calInit() returned %d", retval); warnings.push_back(buf); goto leave; } retval = (*__calDeviceGetCount)(&numDevices); if (retval != CAL_RESULT_OK) { - sprintf(buf, "calDeviceGetCount() returned %d", retval); + snprintf(buf, sizeof(buf), "calDeviceGetCount() returned %d", retval); warnings.push_back(buf); goto leave; } retval = (*__calGetVersion)(&cal_major, &cal_minor, &cal_imp); if (retval != CAL_RESULT_OK) { - sprintf(buf, "calGetVersion() returned %d", retval); + snprintf(buf, sizeof(buf), "calGetVersion() returned %d", retval); warnings.push_back(buf); goto leave; } @@ -227,13 +227,13 @@ void COPROC_ATI::get( for (CALuint i=0; i #endif @@ -68,7 +72,7 @@ int HOST_INFO::get_local_network_info() { char buf[256]; make_random_string("", buf); buf[8] = 0; - sprintf(domain_name, "android_%s", buf); + snprintf(domain_name, sizeof(domain_name), "android_%s", buf); return 0; #endif @@ -107,11 +111,13 @@ void HOST_INFO::make_random_string(const char* salt, char* out) { char buf[1024]; #ifdef ANDROID - sprintf(buf, "%f%s%s%f%s", + snprintf(buf, sizeof(buf), + "%f%s%s%f%s", dtime(), domain_name, ip_addr, d_free, salt ); #else - sprintf(buf, "%d%.15e%s%s%f%s", + snprintf(buf, sizeof(buf), + "%d%.15e%s%s%f%s", getpid(), dtime(), domain_name, ip_addr, d_free, salt ); #endif diff --git a/client/http_curl.cpp b/client/http_curl.cpp index 74461f236a..0bda30ad96 100644 --- a/client/http_curl.cpp +++ b/client/http_curl.cpp @@ -20,8 +20,9 @@ #ifdef _WIN32 #include "boinc_win.h" #ifdef _MSC_VER -#define unlink _unlink -#define chdir _chdir +#define unlink _unlink +#define chdir _chdir +#define snprintf _snprintf #endif #else #include "config.h" @@ -70,13 +71,14 @@ static bool got_expectation_failed = false; static void get_user_agent_string() { if (g_user_agent_string[0]) return; - sprintf(g_user_agent_string, "BOINC client (%s %d.%d.%d)", + snprintf(g_user_agent_string, sizeof(g_user_agent_string), + "BOINC client (%s %d.%d.%d)", gstate.get_primary_platform(), BOINC_MAJOR_VERSION, BOINC_MINOR_VERSION, BOINC_RELEASE ); if (strlen(gstate.client_brand)) { char buf[256]; - sprintf(buf, " (%s)", gstate.client_brand); + snprintf(buf, sizeof(buf), " (%s)", gstate.client_brand); safe_strcat(g_user_agent_string, buf); } } @@ -357,7 +359,9 @@ int HTTP_OP::init_post2( file_offset = offset; retval = file_size(infile, size); if (retval) { - printf("HTTP::init_post2: couldn't get file size\n"); + if (log_flags.http_debug) { + msg_printf(project, MSG_INFO, "[http] HTTP::init_post2: couldn't get file size"); + } return retval; // this will be 0 or ERR_NOT_FOUND } content_length = (int)size - (int)offset; @@ -437,7 +441,7 @@ int HTTP_OP::libcurl_exec( } else { // always want an outfile for the server response, delete when op done bTempOutfile = true; - sprintf(outfile, "http_temp_%d", outfile_seqno++); + snprintf(outfile, sizeof(outfile), "http_temp_%d", outfile_seqno++); } curlEasy = curl_easy_init(); // get a curl_easy handle to use @@ -603,7 +607,7 @@ int HTTP_OP::libcurl_exec( pcurlList = curl_slist_append(pcurlList, g_content_type); if (strlen(gstate.language)) { - sprintf(buf, "Accept-Language: %s", gstate.language); + snprintf(buf, sizeof(buf), "Accept-Language: %s", gstate.language); pcurlList = curl_slist_append(pcurlList, buf); } @@ -611,7 +615,7 @@ int HTTP_OP::libcurl_exec( // if (!is_post && offset>0.0f) { file_offset = offset; - sprintf(buf, "Range: bytes=%.0f-", offset); + snprintf(buf, sizeof(buf), "Range: bytes=%.0f-", offset); pcurlList = curl_slist_append(pcurlList, buf); } @@ -852,7 +856,10 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { } else { curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY); } - sprintf(m_curl_user_credentials, "%s:%s", pi.http_user_name, pi.http_user_passwd); + snprintf(m_curl_user_credentials, sizeof(m_curl_user_credentials), + "%s:%s", + pi.http_user_name, pi.http_user_passwd + ); curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials); } @@ -868,7 +875,10 @@ void HTTP_OP::setup_proxy_session(bool no_proxy) { if ( strlen(pi.socks5_user_passwd) || strlen(pi.socks5_user_name) ) { - sprintf(m_curl_user_credentials, "%s:%s", pi.socks5_user_name, pi.socks5_user_passwd); + snprintf(m_curl_user_credentials, sizeof(m_curl_user_credentials), + "%s:%s", + pi.socks5_user_name, pi.socks5_user_passwd + ); curl_easy_setopt(curlEasy, CURLOPT_PROXYUSERPWD, m_curl_user_credentials); curl_easy_setopt(curlEasy, CURLOPT_PROXYAUTH, CURLAUTH_ANY & ~CURLAUTH_NTLM); } diff --git a/client/log_flags.cpp b/client/log_flags.cpp index dc4b7f410d..7e9386d924 100644 --- a/client/log_flags.cpp +++ b/client/log_flags.cpp @@ -20,7 +20,8 @@ #ifdef _WIN32 #include "boinc_win.h" #ifdef _MSC_VER -#define chdir _chdir +#define chdir _chdir +#define snprintf _snprintf #endif #else #include "config.h" @@ -138,7 +139,7 @@ static void show_exclude_gpu(EXCLUDE_GPU& e) { if (e.device_num < 0) { safe_strcpy(dev, "all"); } else { - sprintf(dev, "%d", e.device_num); + snprintf(dev, sizeof(dev), "%d", e.device_num); } msg_printf(p, MSG_INFO, "Config: excluded GPU. Type: %s. App: %s. Device: %s", diff --git a/client/project.cpp b/client/project.cpp index 2cdb00151e..495972eba0 100644 --- a/client/project.cpp +++ b/client/project.cpp @@ -18,6 +18,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include #include "str_replace.h" @@ -670,7 +674,7 @@ void PROJECT::delete_project_file_symlinks() { for (i=0; iname); + snprintf(link_path, sizeof(link_path), "%s/%s", project_dir(), fref.open_name); + snprintf(file_path, sizeof(file_path), "%s/%s", project_dir(), fip->name); make_soft_link(this, link_path, file_path); } return 0; @@ -888,7 +892,7 @@ const char* PROJECT::project_dir() { if (_project_dir[0] == 0) { char buf[1024]; escape_project_url(master_url, buf); - sprintf(_project_dir, "%s/%s", PROJECTS_DIR, buf); + snprintf(_project_dir, sizeof(_project_dir), "%s/%s", PROJECTS_DIR, buf); } return _project_dir; } diff --git a/client/result.cpp b/client/result.cpp index a2caddd9a0..59690f1bb6 100644 --- a/client/result.cpp +++ b/client/result.cpp @@ -15,7 +15,16 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . +#ifdef _WIN32 +#include "boinc_win.h" +#else +#include "config.h" #include +#endif + +#ifdef _MSC_VER +#define snprintf _snprintf +#endif #include "str_replace.h" #include "parse.h" @@ -388,14 +397,14 @@ int RESULT::write_gui(MIOFILE& out) { // if (avp->gpu_usage.rsc_type) { if (avp->gpu_usage.usage == 1) { - sprintf(resources, + snprintf(resources, sizeof(resources), "%.3g %s + 1 %s", avp->avg_ncpus, cpu_string(avp->avg_ncpus), rsc_name_long(avp->gpu_usage.rsc_type) ); } else { - sprintf(resources, + snprintf(resources, sizeof(resources), "%.3g %s + %.3g %ss", avp->avg_ncpus, cpu_string(avp->avg_ncpus), @@ -404,13 +413,15 @@ int RESULT::write_gui(MIOFILE& out) { ); } } else if (avp->missing_coproc) { - sprintf(resources, "%.3g %s + %s GPU (missing)", + snprintf(resources, sizeof(resources), + "%.3g %s + %s GPU (missing)", avp->avg_ncpus, cpu_string(avp->avg_ncpus), avp->missing_coproc_name ); } else if (!project->non_cpu_intensive && (avp->avg_ncpus != 1)) { - sprintf(resources, "%.3g %s", + snprintf(resources, sizeof(resources), + "%.3g %s", avp->avg_ncpus, cpu_string(avp->avg_ncpus) ); diff --git a/client/rr_sim.cpp b/client/rr_sim.cpp index e62861ae46..71242fe597 100644 --- a/client/rr_sim.cpp +++ b/client/rr_sim.cpp @@ -42,6 +42,10 @@ #include "config.h" #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "client_msgs.h" #include "client_state.h" #include "coproc.h" @@ -50,15 +54,16 @@ using std::vector; -inline void rsc_string(RESULT* rp, char* buf) { +inline void rsc_string(RESULT* rp, char* buf, int len) { APP_VERSION* avp = rp->avp; if (avp->gpu_usage.rsc_type) { - sprintf(buf, "%.2f CPU + %.2f %s", + snprintf(buf, len, + "%.2f CPU + %.2f %s", avp->avg_ncpus, avp->gpu_usage.usage, rsc_name_long(avp->gpu_usage.rsc_type) ); } else { - sprintf(buf, "%.2f CPU", avp->avg_ncpus); + snprintf(buf, len, "%.2f CPU", avp->avg_ncpus); } } @@ -273,7 +278,7 @@ void RR_SIM::pick_jobs_to_run(double reltime) { adjust_rec_sched(rp); if (log_flags.rrsim_detail && !rp->already_selected) { char buf[256]; - rsc_string(rp, buf); + rsc_string(rp, buf, sizeof(buf)); msg_printf(rp->project, MSG_INFO, "[rr_sim_detail] %.2f: starting %s (%s) (%.2fG/%.2fG)", reltime, rp->name, buf, rp->rrsim_flops_left/1e9, rp->rrsim_flops/1e9 @@ -443,7 +448,7 @@ void RR_SIM::simulate() { pbest = rpbest->project; if (log_flags.rr_simulation) { char buf[256]; - rsc_string(rpbest, buf); + rsc_string(rpbest, buf, sizeof(buf)); msg_printf(pbest, MSG_INFO, "[rr_sim] %.2f: %s finishes (%s) (%.2fG/%.2fG)", sim_now + delta_t - gstate.now, diff --git a/client/sandbox.cpp b/client/sandbox.cpp index 20e59f80f1..33bc0dfe39 100644 --- a/client/sandbox.cpp +++ b/client/sandbox.cpp @@ -29,6 +29,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "file_names.h" #include "util.h" @@ -61,7 +65,7 @@ int switcher_exec(const char *util_filename, const char* cmdline) { int retval; std::string output_out, output_err; - sprintf(util_path, "%s/%s", SWITCHER_DIR, util_filename); + snprintf(util_path, sizeof(util_path), "%s/%s", SWITCHER_DIR, util_filename); argv[0] = const_cast(util_filename); // Make a copy of cmdline because parse_command_line modifies it safe_strcpy(command, cmdline); @@ -171,7 +175,7 @@ int kill_via_switcher(int pid) { // client is running as user boinc_master, // we cannot send a signal directly, so use switcher. // - sprintf(cmd, "/bin/kill kill -s KILL %d", pid); + snprintf(cmd, sizeof(cmd), "/bin/kill kill -s KILL %d", pid); return switcher_exec(SWITCHER_FILE_NAME, cmd); } @@ -188,7 +192,7 @@ int remove_project_owned_file_or_dir(const char* path) { char cmd[1024]; if (g_use_sandbox) { - sprintf(cmd, "/bin/rm rm -fR \"%s\"", path); + snprintf(cmd, sizeof(cmd), "/bin/rm rm -fR \"%s\"", path); if (switcher_exec(SWITCHER_FILE_NAME, cmd)) { return ERR_UNLINK; } else { @@ -342,7 +346,7 @@ int client_clean_out_dir( if (except && !strcmp(except, filename)) { continue; } - sprintf(path, "%s/%s", dirpath, filename); + snprintf(path, sizeof(path), "%s/%s", dirpath, filename); if (is_dir(path)) { retval = client_clean_out_dir(path, NULL); if (retval) final_retval = retval; diff --git a/client/scheduler_op.cpp b/client/scheduler_op.cpp index 20389eba12..22d68826cc 100644 --- a/client/scheduler_op.cpp +++ b/client/scheduler_op.cpp @@ -27,6 +27,10 @@ #include #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "filesys.h" #include "parse.h" @@ -102,7 +106,7 @@ int SCHEDULER_OP::init_op_project(PROJECT* p, int r) { if (p->scheduler_urls.size() == 0) { retval = init_master_fetch(p); if (retval) { - sprintf(err_msg, + snprintf(err_msg, sizeof(err_msg), "Scheduler list fetch initialization failed: %d\n", retval ); project_rpc_backoff(p, err_msg); @@ -123,7 +127,7 @@ int SCHEDULER_OP::init_op_project(PROJECT* p, int r) { retval = start_rpc(p); } if (retval) { - sprintf(err_msg, + snprintf(err_msg, sizeof(err_msg), "scheduler request to %s failed: %s\n", p->get_scheduler_url(url_index, url_random), boincerror(retval) ); @@ -161,7 +165,7 @@ void SCHEDULER_OP::project_rpc_backoff(PROJECT* p, const char *reason_msg) { } if (p->master_fetch_failures >= gstate.master_fetch_retry_cap) { - sprintf(buf, + snprintf(buf, sizeof(buf), "%d consecutive failures fetching scheduler list", p->master_fetch_failures ); @@ -459,7 +463,7 @@ bool SCHEDULER_OP::poll() { // master file fetch failed. // char buf[256]; - sprintf(buf, "Scheduler list fetch failed: %s", + snprintf(buf, sizeof(buf), "Scheduler list fetch failed: %s", boincerror(http_op.http_op_retval) ); cur_proj->master_fetch_failures++; diff --git a/client/sysmon_win.cpp b/client/sysmon_win.cpp index a9728338ef..cec8e692a4 100644 --- a/client/sysmon_win.cpp +++ b/client/sysmon_win.cpp @@ -17,6 +17,10 @@ #include "boinc_win.h" +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "diagnostics.h" #include "error_numbers.h" #include "filesys.h" @@ -357,7 +361,7 @@ static void windows_detect_autoproxy_settings() { } if (log_flags.proxy_debug) { - sprintf_s(buf, "proxy detected %s:%d", purl.host, purl.port); + snprintf(buf, sizeof(buf), "proxy detected %s:%d", purl.host, purl.port); safe_strcat(msg, buf); } } diff --git a/client/time_stats.cpp b/client/time_stats.cpp index 6e0c31b879..738eda538f 100644 --- a/client/time_stats.cpp +++ b/client/time_stats.cpp @@ -30,6 +30,10 @@ #endif #endif +#ifdef _MSC_VER +#define snprintf _snprintf +#endif + #include "error_numbers.h" #include "filesys.h" #include "parse.h" @@ -221,10 +225,14 @@ void CLIENT_TIME_STATS::update(int suspend_reason, int _gpu_suspend_reason) { log_append("power_off", last_update); char buf[256]; #ifndef SIM - sprintf(buf, "platform %s", gstate.get_primary_platform()); + snprintf(buf, sizeof(buf), + "platform %s", + gstate.get_primary_platform() + ); log_append(buf, gstate.now); #endif - sprintf(buf, "version %d.%d.%d", + snprintf(buf, sizeof(buf), + "version %d.%d.%d", BOINC_MAJOR_VERSION, BOINC_MINOR_VERSION, BOINC_RELEASE ); log_append(buf, gstate.now); diff --git a/client/work_fetch.cpp b/client/work_fetch.cpp index fe96ebc77c..53982aedaf 100644 --- a/client/work_fetch.cpp +++ b/client/work_fetch.cpp @@ -15,14 +15,17 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -#include - #include "cpp.h" #ifdef _WIN32 #include "boinc_win.h" #else #include "config.h" +#include +#endif + +#ifdef _MSC_VER +#define snprintf _snprintf #endif #include "util.h" @@ -299,7 +302,8 @@ void RSC_WORK_FETCH::print_state(const char* name) { RSC_PROJECT_WORK_FETCH& rpwf = project_state(p); double bt = rpwf.backoff_time>gstate.now?rpwf.backoff_time-gstate.now:0; if (bt) { - sprintf(buf, " (resource backoff: %.2f, inc %.2f)", + snprintf(buf, sizeof(buf), + " (resource backoff: %.2f, inc %.2f)", bt, rpwf.backoff_interval ); } else { @@ -351,15 +355,22 @@ void PROJECT_WORK_FETCH::rr_init(PROJECT* p) { void PROJECT_WORK_FETCH::print_state(PROJECT* p) { char buf[1024], buf2[1024]; if (project_reason) { - sprintf(buf, "can't request work: %s", project_reason_string(p, buf2, sizeof(buf2))); + snprintf(buf, sizeof(buf), + "can't request work: %s", + project_reason_string(p, buf2, sizeof(buf2)) + ); } else { safe_strcpy(buf, "can request work"); } if (p->min_rpc_time > gstate.now) { - sprintf(buf2, " (%.2f sec)", p->min_rpc_time - gstate.now); + snprintf(buf2, sizeof(buf2), + " (%.2f sec)", + p->min_rpc_time - gstate.now + ); safe_strcat(buf, buf2); } - msg_printf(p, MSG_INFO, "[work_fetch] REC %.3f prio %.3f %s", + msg_printf(p, MSG_INFO, + "[work_fetch] REC %.3f prio %.3f %s", rec, p->sched_priority, buf @@ -816,12 +827,13 @@ void WORK_FETCH::compute_shares() { void WORK_FETCH::request_string(char* buf, int len) { char buf2[256]; - sprintf(buf, + snprintf(buf, len, "[work_fetch] request: CPU (%.2f sec, %.2f inst)", rsc_work_fetch[0].req_secs, rsc_work_fetch[0].req_instances ); for (int i=1; i