From 2c068b76dcab972eda2a30c147e629bffc60072a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 11 Feb 2009 22:36:33 +0000 Subject: [PATCH] - lib: implement APP_INIT_DATA::copy() with assignments instead of memcpy(). This protects against any future double-free bugs. svn path=/trunk/boinc/; revision=17212 --- checkin_notes | 7 +++++++ lib/app_ipc.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- lib/app_ipc.h | 1 + 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/checkin_notes b/checkin_notes index b4f9e489d4..d696651c80 100644 --- a/checkin_notes +++ b/checkin_notes @@ -1458,3 +1458,10 @@ Rom 11 Feb 2009 clientgui/ ViewWork.cpp + +David 11 Feb 2009 + - lib: implement APP_INIT_DATA::copy() with assignments instead of + memcpy(). This protects against any future double-free bugs. + + lib/ + app_ipc.h,cpp diff --git a/lib/app_ipc.cpp b/lib/app_ipc.cpp index fdd946fc6c..509f031e17 100644 --- a/lib/app_ipc.cpp +++ b/lib/app_ipc.cpp @@ -70,9 +70,48 @@ APP_INIT_DATA &APP_INIT_DATA::operator=(const APP_INIT_DATA& a) { } void APP_INIT_DATA::copy(const APP_INIT_DATA& a) { - memcpy(this, &a, sizeof(APP_INIT_DATA)); + // memcpy the strings + memcpy( &app_name[0], &a.app_name[0], 256 ); + memcpy( &symstore[0], &a.symstore[0], 256 ); + memcpy( &acct_mgr_url[0], &a.acct_mgr_url[0], 256 ); + memcpy( &user_name[0], &a.user_name[0], 256 ); + memcpy( &team_name[0], &a.team_name[0], 256 ); + memcpy( &project_dir[0], &a.project_dir[0], 256 ); + memcpy( &boinc_dir[0], &a.boinc_dir[0], 256 ); + memcpy( &wu_name[0], &a.wu_name[0], 256 ); + memcpy( &authenticator[0], &a.authenticator[0], 256 ); + + // use assignment for the rest, especially the classes + // (such that the overloaded operators are called!) + major_version = a.major_version; + minor_version = a.minor_version; + release = a.release; + app_version = a.app_version; + userid = a.userid; + teamid = a.teamid; + hostid = a.hostid; + slot = a.slot; + user_total_credit = a.user_total_credit; + user_expavg_credit = a.user_expavg_credit; + host_total_credit = a.host_total_credit; + host_expavg_credit = a.host_expavg_credit; + resource_share_fraction = a.resource_share_fraction; + host_info = a.host_info; + proxy_info = a.proxy_info; + global_prefs = a.global_prefs; + rsc_fpops_est = a.rsc_fpops_est; + rsc_fpops_bound = a.rsc_fpops_bound; + rsc_memory_bound = a.rsc_memory_bound; + rsc_disk_bound = a.rsc_disk_bound; + computation_deadline = a.computation_deadline; + fraction_done_start = a.fraction_done_start; + fraction_done_end = a.fraction_done_end; + checkpoint_period = a.checkpoint_period; + wu_cpu_time = a.wu_cpu_time; if (a.project_preferences) { project_preferences = strdup(a.project_preferences); + } else { + project_preferences = NULL; } } diff --git a/lib/app_ipc.h b/lib/app_ipc.h index 62fb9f65cd..4f2fa45dae 100644 --- a/lib/app_ipc.h +++ b/lib/app_ipc.h @@ -142,6 +142,7 @@ public: #endif // parsed version of main init file +// If you add anything here, update copy() // struct APP_INIT_DATA { int major_version;