@@ -92,20 +92,20 @@ using std::string;
92
92
93
93
bool shared_file_exists (std::string& filename) {
94
94
char path[MAXPATHLEN];
95
- sprintf (path, " shared/%s" , filename.c_str ());
95
+ snprintf (path, sizeof (path) , " shared/%s" , filename.c_str ());
96
96
if (filename.size () && boinc_file_exists (path)) return true ;
97
97
return false ;
98
98
}
99
99
100
100
void shared_delete_file (std::string& filename) {
101
101
char path[MAXPATHLEN];
102
- sprintf (path, " shared/%s" , filename.c_str ());
102
+ snprintf (path, sizeof (path) , " shared/%s" , filename.c_str ());
103
103
boinc_delete_file (path);
104
104
}
105
105
106
106
int shared_stat (std::string& filename, struct stat * stat_file) {
107
107
char path[MAXPATHLEN];
108
- sprintf (path, " shared/%s" , filename.c_str ());
108
+ snprintf (path, sizeof (path) , " shared/%s" , filename.c_str ());
109
109
return stat (path, stat_file);
110
110
}
111
111
@@ -114,7 +114,7 @@ bool read_fraction_done(double& frac_done, VBOX_VM& vm) {
114
114
char buf[256 ];
115
115
double temp, frac = 0 ;
116
116
117
- sprintf (path, " shared/%s" , vm.fraction_done_filename .c_str ());
117
+ snprintf (path, sizeof (path) , " shared/%s" , vm.fraction_done_filename .c_str ());
118
118
FILE* f = fopen (path, " r" );
119
119
if (!f) return false ;
120
120
@@ -147,7 +147,7 @@ void read_completion_file_info(unsigned long& exit_code, bool& is_notice, string
147
147
exit_code = 0 ;
148
148
message = " " ;
149
149
150
- sprintf (path, " shared/%s" , vm.completion_trigger_file .c_str ());
150
+ snprintf (path, sizeof (path) , " shared/%s" , vm.completion_trigger_file .c_str ());
151
151
FILE* f = fopen (path, " r" );
152
152
if (f) {
153
153
if (fgets (buf, 1024 , f) != NULL ) {
@@ -170,7 +170,7 @@ void read_temporary_exit_file_info(int& temp_delay, bool& is_notice, string& mes
170
170
temp_delay = 0 ;
171
171
message = " " ;
172
172
173
- sprintf (path, " shared/%s" , vm.temporary_exit_trigger_file .c_str ());
173
+ snprintf (path, sizeof (path) , " shared/%s" , vm.temporary_exit_trigger_file .c_str ());
174
174
FILE* f = fopen (path, " r" );
175
175
if (f) {
176
176
if (fgets (buf, 1024 , f) != NULL ) {
@@ -249,16 +249,16 @@ void set_floppy_image(APP_INIT_DATA& aid, VBOX_VM& vm) {
249
249
scratch = " BOINC_USERNAME=" + string (aid.user_name ) + " \n " ;
250
250
scratch += " BOINC_AUTHENTICATOR=" + string (aid.authenticator ) + " \n " ;
251
251
252
- sprintf (buf, " %d" , aid.userid );
252
+ snprintf (buf, sizeof (buf) , " %d" , aid.userid );
253
253
scratch += " BOINC_USERID=" + string (buf) + " \n " ;
254
254
255
- sprintf (buf, " %d" , aid.hostid );
255
+ snprintf (buf, sizeof (buf) , " %d" , aid.hostid );
256
256
scratch += " BOINC_HOSTID=" + string (buf) + " \n " ;
257
257
258
- sprintf (buf, " %.17g" , aid.user_total_credit );
258
+ snprintf (buf, sizeof (buf) , " %.17g" , aid.user_total_credit );
259
259
scratch += " BOINC_USER_TOTAL_CREDIT=" + string (buf) + " \n " ;
260
260
261
- sprintf (buf, " %.17g" , aid.host_total_credit );
261
+ snprintf (buf, sizeof (buf) , " %.17g" , aid.host_total_credit );
262
262
scratch += " BOINC_HOST_TOTAL_CREDIT=" + string (buf) + " \n " ;
263
263
}
264
264
vm.write_floppy (scratch);
@@ -270,7 +270,7 @@ void set_floppy_image(APP_INIT_DATA& aid, VBOX_VM& vm) {
270
270
void report_web_graphics_url (VBOX_VM& vm) {
271
271
char buf[256 ];
272
272
if (vm.pf_host_port && !boinc_file_exists (" graphics_app" )) {
273
- sprintf (buf, " http://localhost:%d" , vm.pf_host_port );
273
+ snprintf (buf, sizeof (buf) , " http://localhost:%d" , vm.pf_host_port );
274
274
vboxlog_msg (" Detected: Web Application Enabled (%s)" , buf);
275
275
boinc_web_graphics_url (buf);
276
276
}
@@ -281,7 +281,7 @@ void report_web_graphics_url(VBOX_VM& vm) {
281
281
void report_remote_desktop_info (VBOX_VM& vm) {
282
282
char buf[256 ];
283
283
if (vm.rd_host_port ) {
284
- sprintf (buf, " localhost:%d" , vm.rd_host_port );
284
+ snprintf (buf, sizeof (buf) , " localhost:%d" , vm.rd_host_port );
285
285
vboxlog_msg (" Detected: Remote Desktop Enabled (%s)" , buf);
286
286
boinc_remote_desktop_addr (buf);
287
287
}
@@ -295,7 +295,7 @@ void check_trickle_triggers(VBOX_VM& vm) {
295
295
std::string text;
296
296
for (unsigned int i=0 ; i<vm.trickle_trigger_files .size (); i++) {
297
297
strcpy (filename, vm.trickle_trigger_files [i].c_str ());
298
- sprintf (path, " shared/%s" , filename);
298
+ snprintf (path, sizeof (path) , " shared/%s" , filename);
299
299
if (!boinc_file_exists (path)) continue ;
300
300
vboxlog_msg (" Reporting a trickle. (%s)" , filename);
301
301
retval = read_file_string (path, text);
@@ -322,7 +322,7 @@ void check_intermediate_uploads(VBOX_VM& vm) {
322
322
char filename[256 ], path[MAXPATHLEN];
323
323
for (unsigned int i=0 ; i<vm.intermediate_upload_files .size (); i++) {
324
324
strcpy (filename, vm.intermediate_upload_files [i].file .c_str ());
325
- sprintf (path, " shared/%s" , filename);
325
+ snprintf (path, sizeof (path) , " shared/%s" , filename);
326
326
if (!boinc_file_exists (path)) continue ;
327
327
if (!vm.intermediate_upload_files [i].reported && !vm.intermediate_upload_files [i].ignore ) {
328
328
vboxlog_msg (" Reporting an intermediate file. (%s)" , vm.intermediate_upload_files [i].file .c_str ());
@@ -354,7 +354,7 @@ void check_trickle_period(double& elapsed_time, double& trickle_period) {
354
354
}
355
355
last_trickle_report_time = elapsed_time;
356
356
vboxlog_msg (" Status Report: Trickle-Up Event." );
357
- sprintf (buf,
357
+ snprintf (buf, sizeof (buf) ,
358
358
" <cpu_time>%f</cpu_time>" , last_trickle_report_time
359
359
);
360
360
int retval = boinc_send_trickle_up (
@@ -629,7 +629,7 @@ int main(int argc, char** argv) {
629
629
pVM->vm_master_name += " standalone" ;
630
630
pVM->vm_master_description = " standalone" ;
631
631
if (pVM->enable_floppyio ) {
632
- sprintf (buf, " %s.%s" ,
632
+ snprintf (buf, sizeof (buf) , " %s.%s" ,
633
633
FLOPPY_IMAGE_FILENAME, FLOPPY_IMAGE_FILENAME_EXTENSION
634
634
);
635
635
pVM->floppy_image_filename = buf;
@@ -638,13 +638,13 @@ int main(int argc, char** argv) {
638
638
pVM->vm_master_name += md5_string (std::string (aid.result_name )).substr (0 , 16 );
639
639
pVM->vm_master_description = aid.result_name ;
640
640
if (vm_image) {
641
- sprintf (buf, " %s_%d.%s" ,
641
+ snprintf (buf, sizeof (buf) , " %s_%d.%s" ,
642
642
IMAGE_FILENAME, vm_image, IMAGE_FILENAME_EXTENSION
643
643
);
644
644
pVM->image_filename = buf;
645
645
}
646
646
if (pVM->enable_floppyio ) {
647
- sprintf (buf, " %s_%d.%s" ,
647
+ snprintf (buf, sizeof (buf) , " %s_%d.%s" ,
648
648
FLOPPY_IMAGE_FILENAME, aid.slot ,
649
649
FLOPPY_IMAGE_FILENAME_EXTENSION
650
650
);
@@ -666,9 +666,9 @@ int main(int argc, char** argv) {
666
666
ncpus = 32.0 ;
667
667
}
668
668
if (ncpus) {
669
- sprintf (buf, " %d" , (int )ceil (ncpus));
669
+ snprintf (buf, sizeof (buf) , " %d" , (int )ceil (ncpus));
670
670
} else {
671
- sprintf (buf, " %d" , (int )ceil (aid.ncpus ));
671
+ snprintf (buf, sizeof (buf) , " %d" , (int )ceil (aid.ncpus ));
672
672
}
673
673
pVM->vm_cpu_count = buf;
674
674
} else {
@@ -1065,7 +1065,7 @@ int main(int argc, char** argv) {
1065
1065
if ((unsigned )retval == VBOX_E_INVALID_OBJECT_STATE) {
1066
1066
vboxlog_msg (" ERROR: VM task failed to pause, rescheduling task for a later time." );
1067
1067
pVM->poweroff ();
1068
- sprintf (buf,
1068
+ snprintf (buf, sizeof (buf) ,
1069
1069
" VM suspend failed. Will exit and restart in %d sec." ,
1070
1070
RESTART_DELAY
1071
1071
);
@@ -1078,7 +1078,7 @@ int main(int argc, char** argv) {
1078
1078
if ((unsigned )retval == VBOX_E_INVALID_OBJECT_STATE) {
1079
1079
vboxlog_msg (" ERROR: VM task failed to resume, rescheduling task for a later time." );
1080
1080
pVM->poweroff ();
1081
- sprintf (buf,
1081
+ snprintf (buf, sizeof (buf) ,
1082
1082
" VM resume failed. Will exit and restart in %d sec." ,
1083
1083
RESTART_DELAY
1084
1084
);
@@ -1157,7 +1157,7 @@ int main(int argc, char** argv) {
1157
1157
//
1158
1158
vboxlog_msg (" ERROR: Checkpoint maintenance failed, rescheduling task for a later time. (%d)" , retval);
1159
1159
pVM->poweroff ();
1160
- sprintf (buf,
1160
+ snprintf (buf, sizeof (buf) ,
1161
1161
" VM snapshot failed. Will exit and restart in %d sec." ,
1162
1162
RESTART_DELAY
1163
1163
);
0 commit comments