From 35af4511d252d38e1070423874a3cd542bac6f36 Mon Sep 17 00:00:00 2001 From: Michael Gary Date: Thu, 11 Jul 2002 01:09:53 +0000 Subject: [PATCH] Added debug code and error catching, fixed flaw in timekeeping, removed unused tests. svn path=/trunk/boinc/; revision=174 --- api/Makefile.in | 3 +- api/api.C | 58 +++++++++++-- client/app.C | 84 ++++++++++++++----- client/app.h | 3 +- client/client_state.C | 110 +++++++++++++++++++++++-- client/client_types.C | 81 +++++++++++++++--- client/cs_apps.C | 5 +- client/cs_files.C | 23 +++++- client/cs_scheduler.C | 16 +++- client/file_names.C | 35 +++++++- client/file_xfer.C | 30 ++++++- client/filesys.C | 44 +++++++--- client/hostinfo.C | 10 ++- client/hostinfo_unix.C | 12 ++- client/http.C | 133 ++++++++++++++++++++++++++++-- client/log_flags.C | 5 +- client/main.C | 6 ++ client/net_stats.C | 10 ++- client/scheduler_op.C | 18 +++- client/speed_stats.C | 39 +++++++-- client/time_stats.C | 5 +- client/util.C | 25 +++++- configure | 2 +- configure.in | 2 +- db/db_mysql.C | 8 +- db/mysql_util.C | 22 ++++- lib/crypt.C | 136 ++++++++++++++++++++++++++----- {client => lib}/error_numbers.h | 4 + lib/md5_file.C | 23 +++++- lib/parse.C | 70 +++++++++++++++- lib/shmem.C | 6 +- sched/Makefile.in | 8 +- sched/feeder.C | 5 +- sched/file_upload_handler.C | 11 ++- sched/handle_request.C | 7 +- sched/main.C | 3 +- sched/sched_shmem.C | 6 +- sched/sched_shmem.h | 2 + sched/server_types.C | 15 ++-- test/master.html | 4 +- test/max_water_prefs.xml | 2 - test/min_water_prefs.xml | 2 - test/normal_water_prefs.xml | 2 - test/prefs1.xml | 2 +- test/test_max_water_prefs.php | 30 ------- test/test_min_water_prefs.php | 30 ------- test/test_normal_water_prefs.php | 31 ------- tools/add.C | 1 + tools/backend_lib.C | 22 ++++- tools/process_result_template.C | 7 +- 50 files changed, 972 insertions(+), 246 deletions(-) rename {client => lib}/error_numbers.h (92%) mode change 100644 => 100755 delete mode 100644 test/max_water_prefs.xml delete mode 100644 test/min_water_prefs.xml delete mode 100644 test/normal_water_prefs.xml delete mode 100755 test/test_max_water_prefs.php delete mode 100755 test/test_min_water_prefs.php delete mode 100755 test/test_normal_water_prefs.php diff --git a/api/Makefile.in b/api/Makefile.in index 04269ce7d1..b932277322 100644 --- a/api/Makefile.in +++ b/api/Makefile.in @@ -5,7 +5,8 @@ VPATH = @srcdir@ VERSION = 1 -CFLAGS = -g -Wall -I../lib/ +CFLAGS = -g -Wall @DEFS@ \ + -I@top_srcdir@/lib/ CC = @CC@ $(CFLAGS) diff --git a/api/api.C b/api/api.C index 8d4ffde7c3..6b5f9a080a 100644 --- a/api/api.C +++ b/api/api.C @@ -37,8 +37,17 @@ #include #include "parse.h" #include "api.h" +#include "error_numbers.h" int MFILE::open(char* path, char* mode) { + if(path==NULL) { + fprintf(stderr, "error: MFILE.open: unexpected NULL pointer path\n"); + return ERR_NULL; + } + if(mode==NULL) { + fprintf(stderr, "error: MFILE.open: unexpected NULL pointer mode\n"); + return ERR_NULL; + } buf = 0; len = 0; f = fopen(path, mode); @@ -50,7 +59,10 @@ int MFILE::printf(char* format, ...) { va_list ap; char buf2[4096]; int n, k; - + if(format==NULL) { + fprintf(stderr, "error: MFILE.printf: unexpected NULL pointer format\n"); + return ERR_NULL; + } va_start(ap, format); k = vsprintf(buf2, format, ap); va_end(ap); @@ -76,6 +88,10 @@ int MFILE::_putchar(char c) { } int MFILE::puts(char* p) { + if(p==NULL) { + fprintf(stderr, "error: MFILE.puts: unexpected NULL pointer p\n"); + return ERR_NULL; + } int n = strlen(p); buf = (char*)realloc(buf, len+n); strncpy(buf+len, p, n); @@ -97,6 +113,9 @@ int MFILE::flush() { } void write_core_file(FILE* f, APP_IN& ai) { + if(f==NULL) { + fprintf(stderr, "error: write_core_file: unexpected NULL pointer f\n"); + } fprintf(f, "%d\n" "%d\n" @@ -117,7 +136,9 @@ void write_core_file(FILE* f, APP_IN& ai) { void parse_core_file(FILE* f, APP_IN& ai) { char buf[256]; - + if(f==NULL) { + fprintf(stderr, "error: parse_core_file: unexpected NULL pointer f\n"); + } while (fgets(buf, 256, f)) { if (match_tag(buf, "")) { strcpy(ai.app_preferences, ""); @@ -139,6 +160,9 @@ void parse_core_file(FILE* f, APP_IN& ai) { } void write_app_file(FILE* f, APP_OUT& ao) { + if(f==NULL) { + fprintf(stderr, "error: write_app_file: unexpected NULL pointer f\n"); + } fprintf(f, "%f\n" "%f\n", @@ -152,6 +176,9 @@ void write_app_file(FILE* f, APP_OUT& ao) { void parse_app_file(FILE* f, APP_OUT& ao) { char buf[256]; + if(f==NULL) { + fprintf(stderr, "error: parse_app_file: unexpected NULL pointer f\n"); + } while (fgets(buf, 256, f)) { if (parse_double(buf, "", ao.percent_done)) continue; else if (parse_double(buf, "", @@ -162,6 +189,12 @@ void parse_app_file(FILE* f, APP_OUT& ao) { } void write_init_file(FILE* f, char *file_name, int fdesc, int input_file ) { + if(f==NULL) { + fprintf(stderr, "error: write_init_file: unexpected NULL pointer f\n"); + } + if(file_name==NULL) { + fprintf(stderr, "error: write_init_file: unexpected NULL pointer file_name\n"); + } if( input_file ) { fprintf( f, "%s\n", file_name ); fprintf( f, "%d\n", fdesc ); @@ -174,7 +207,9 @@ void write_init_file(FILE* f, char *file_name, int fdesc, int input_file ) { void parse_init_file(FILE* f) { char buf[256],filename[256]; int filedesc,fd,retval; - + if(f==NULL) { + fprintf(stderr, "error: parse_init_file: unexpected NULL pointer f\n"); + } while (fgets(buf, 256, f)) { if (parse_str(buf, "", filename)) { if (fgets(buf, 256, f)) { @@ -247,7 +282,14 @@ int boinc_resolve_link(char *file_name, char *resolved_name) { FILE *fp; char buf[512]; - + if(file_name==NULL) { + fprintf(stderr, "error: boinc_resolve_link: unexpected NULL pointer file_name\n"); + return ERR_NULL; + } + if(resolved_name==NULL) { + fprintf(stderr, "error: boinc_resolve_link: unexpected NULL pointer resolved_name\n"); + return ERR_NULL; + } // Open the file and load the first line fp = fopen( file_name, "r" ); if (!fp) { @@ -327,16 +369,22 @@ void on_timer(int a) { int set_timer(double period) { int retval=0; + if(period<0) { + fprintf(stderr, "error: set_timer: negative period\n"); + return ERR_NEG; + } +#if HAVE_SIGNAL_H +#if HAVE_SYS_TIME_H struct sigaction sa; sa.sa_handler = on_timer; sa.sa_flags = 0; sigaction(SIGVTALRM, &sa, NULL); -#ifdef HAVE_SYS_TIME_H itimerval value; value.it_value.tv_sec = (int)period; value.it_value.tv_usec = ((int)(period*1000000))%1000000; value.it_interval = value.it_value; retval = setitimer(ITIMER_VIRTUAL, &value, NULL); +#endif #endif return retval; } diff --git a/client/app.C b/client/app.C index 65007a6117..64bd922a4c 100644 --- a/client/app.C +++ b/client/app.C @@ -22,6 +22,7 @@ // Shouldn't depend on CLIENT_STATE. #include "windows_cpp.h" +#include "error_numbers.h" #ifdef _WIN32 #include @@ -73,7 +74,12 @@ void parse_command_line(char* p, char** argv) { char** pp = argv; bool space = true; - + if(p==NULL) { + fprintf(stderr, "error: parse_command_line: unexpected NULL pointer p\n"); + } + if(argv==NULL) { + fprintf(stderr, "error: parse_command_line: unexpected NULL pointer argv\n"); + } while (*p) { if (isspace(*p)) { *p = 0; @@ -91,6 +97,9 @@ void parse_command_line(char* p, char** argv) { static void print_argv(char** argv) { int i; + if(argv==NULL) { + fprintf(stderr, "error: print_argv: unexpected NULL pointer argv\n"); + } for (i=0; argv[i]; i++) { fprintf(stderr, "argv[%d]: %s\n", i, argv[i]); } @@ -104,10 +113,14 @@ ACTIVE_TASK::ACTIVE_TASK() { exit_status = 0; signal = 0; strcpy(dirname, ""); - cpu_time = 0; + prev_cpu_time = 0; } int ACTIVE_TASK::init(RESULT* rp) { + if(rp==NULL) { + fprintf(stderr, "error: ACTIVE_TASK.init: unexpected NULL pointer rp\n"); + return ERR_NULL; + } result = rp; wup = rp->wup; app_version = wup->avp; @@ -125,15 +138,13 @@ int ACTIVE_TASK::start(bool first_time) { FILE *prefs_fd,*init_file; APP_IN app_prefs; - if(first_time) prev_cpu_time = 0; - cpu_time = 0; + prev_cpu_time = 0; // These should be chosen in a better manner app_prefs.graphics.xsize = 640; app_prefs.graphics.ysize = 480; app_prefs.graphics.refresh_period = 5; app_prefs.checkpoint_period = 5; app_prefs.poll_period = 5; - app_prefs.cpu_time = prev_cpu_time; // Write out the app prefs sprintf( prefs_path, "%s/%s", dirname, CORE_TO_APP_FILE ); @@ -315,7 +326,6 @@ int ACTIVE_TASK::start(bool first_time) { } pid_handle = process_info.hProcess; - #endif #ifdef macintosh @@ -327,23 +337,30 @@ int ACTIVE_TASK::start(bool first_time) { void ACTIVE_TASK::request_exit(int seconds) { int retval; + if(seconds<0) { + fprintf(stderr, "error: ACTIVE_TASK.request_exit: negative seconds\n"); + seconds=0; + } #if HAVE_SIGNAL_H #if HAVE_SYS_TYPES_H retval = kill(pid, SIGTERM); sleep(seconds); - if(retval) kill(pid, SIGKILL); + while(retval) retval=kill(pid, SIGKILL); #endif #endif #ifdef _WIN32 - //retval = ExitProcess(); + retval = TerminateProcess(pid_handle, -1);//exit codes should be changed sleep(seconds); - //if(retval) TerminateProcess(); + while(retval) retval=TerminateProcess(pid_handle, -1); #endif } int ACTIVE_TASK_SET::insert(ACTIVE_TASK* atp) { int retval; - + if(atp==NULL) { + fprintf(stderr, "error: ACTIVE_TASK.insert: unexpected NULL pointer atp\n"); + return ERR_NULL; + } get_slot_dir(atp->slot, atp->dirname); clean_out_dir(atp->dirname); retval = atp->start(true); @@ -451,7 +468,10 @@ bool ACTIVE_TASK_SET::poll() { ACTIVE_TASK* ACTIVE_TASK_SET::lookup_pid(int pid) { unsigned int i; ACTIVE_TASK* atp; - + if(pid<0) { + fprintf(stderr, "error: ACTIVE_TASK_SET.lookup_pid: negatvie pid\n"); + return 0; + } for (i=0; ipid == pid) return atp; @@ -479,10 +499,11 @@ void ACTIVE_TASK_SET::unsuspend_all() { void ACTIVE_TASK_SET::exit_tasks() { unsigned int i; - ACTIVE_TASK* atp; + ACTIVE_TASK *atp; for (i=0; irequest_exit(0); + atp->update_time(); } } @@ -499,7 +520,6 @@ void ACTIVE_TASK::unsuspend() { } #else void ACTIVE_TASK::suspend() { - prev_cpu_time = cpu_time; kill(this->pid, SIGSTOP); } @@ -510,7 +530,10 @@ void ACTIVE_TASK::unsuspend() { int ACTIVE_TASK_SET::remove(ACTIVE_TASK* atp) { vector::iterator iter; - + if(atp==NULL) { + fprintf(stderr, "error: ACTIVE_TASK_SET.remove: unexpected NULL pointer atp\n"); + return ERR_NULL; + } iter = active_tasks.begin(); while (iter != active_tasks.end()) { if (*iter == atp) { @@ -556,7 +579,8 @@ bool ACTIVE_TASK::update_time() { if(!app_fp) return false; parse_app_file(app_fp, ao); if(!ao.checkpointed) return false; - cpu_time = ao.cpu_time_at_checkpoint + prev_cpu_time; + result->cpu_time += ao.cpu_time_at_checkpoint - prev_cpu_time; + prev_cpu_time = ao.cpu_time_at_checkpoint; return true; } @@ -572,20 +596,22 @@ bool ACTIVE_TASK_SET::poll_time() { } int ACTIVE_TASK::write(FILE* fout) { + if(fout==NULL) { + fprintf(stderr, "error: ACTIVE_TASK.write: unexpected NULL pointer fout\n"); + return ERR_NULL; + } fprintf(fout, "\n" " %s\n" " %s\n" " %d\n" " %d\n" - " %f\n" " %f\n" "\n", result->project->master_url, result->name, app_version->version_num, slot, - cpu_time, prev_cpu_time ); return 0; @@ -595,10 +621,16 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) { char buf[256], result_name[256], project_master_url[256]; int app_version_num=0; PROJECT* project; - + if(fin==NULL) { + fprintf(stderr, "error: ACTIVE_TASK.parse: unexpected NULL pointer fin\n"); + return ERR_NULL; + } + if(cs==NULL) { + fprintf(stderr, "error: ACTIVE_TASK.parse: unexpected NULL pointer cs\n"); + return ERR_NULL; + } strcpy(result_name, ""); strcpy(project_master_url, ""); - cpu_time = 0; while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) { project = cs->lookup_project(project_master_url); @@ -628,7 +660,6 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) { else if (parse_str(buf, "", project_master_url)) continue; else if (parse_int(buf, "", app_version_num)) continue; else if (parse_int(buf, "", slot)) continue; - else if (parse_double(buf, "", cpu_time)) continue; else if (parse_double(buf, "", prev_cpu_time)) continue; else fprintf(stderr, "ACTIVE_TASK::parse(): unrecognized %s\n", buf); } @@ -637,6 +668,10 @@ int ACTIVE_TASK::parse(FILE* fin, CLIENT_STATE* cs) { int ACTIVE_TASK_SET::write(FILE* fout) { unsigned int i; + if(fout==NULL) { + fprintf(stderr, "error: ACTIVE_TASK_SET.write: unexpected NULL pointer fout\n"); + return ERR_NULL; + } fprintf(fout, "\n"); for (i=0; iwrite(fout); @@ -649,7 +684,14 @@ int ACTIVE_TASK_SET::parse(FILE* fin, CLIENT_STATE* cs) { ACTIVE_TASK* atp; char buf[256]; int retval; - + if(fin==NULL) { + fprintf(stderr, "error: ACTIVE_TASK_SET.parse: unexpected NULL pointer fin\n"); + return ERR_NULL; + } + if(cs==NULL) { + fprintf(stderr, "error: ACTIVE_TASK_SET.parse: unexpected NULL pointer cs\n"); + return ERR_NULL; + } while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (match_tag(buf, "")) { diff --git a/client/app.h b/client/app.h index 7c8b0a8a9a..e7b6706a60 100644 --- a/client/app.h +++ b/client/app.h @@ -62,8 +62,7 @@ public: int exit_status; int signal; char dirname[256]; // directory where process runs - double cpu_time; // total CPU time - double prev_cpu_time; // CPU time from previous processes + double prev_cpu_time; ACTIVE_TASK(); int init(RESULT*); diff --git a/client/client_state.C b/client/client_state.C index 8d430cef7f..92de9530b2 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -18,6 +18,7 @@ // #include "windows_cpp.h" +#include "error_numbers.h" #include #include @@ -52,7 +53,10 @@ CLIENT_STATE::CLIENT_STATE() { int CLIENT_STATE::init(PREFS* p) { nslots = 1; unsigned int i; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.init: unexpected NULL pointer p\n"); + return ERR_NULL; + } prefs = p; // copy all PROJECTs from the prefs to the client state. @@ -267,6 +271,7 @@ int CLIENT_STATE::make_slot_dirs() { int CLIENT_STATE::exit_tasks() { active_tasks.exit_tasks(); + active_tasks.poll_time(); return 0; } @@ -325,6 +330,10 @@ int CLIENT_STATE::write_state_file() { } PROJECT* CLIENT_STATE::lookup_project(char* master_url) { + if(master_url==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_project: unexpected NULL pointer master_url\n"); + return 0; + } for (unsigned int i=0; imaster_url)) { return projects[i]; @@ -334,6 +343,14 @@ PROJECT* CLIENT_STATE::lookup_project(char* master_url) { } APP* CLIENT_STATE::lookup_app(PROJECT* p, char* name) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_app: unexpected NULL pointer p\n"); + return 0; + } + if(name==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_app: unexpected NULL pointer name\n"); + return 0; + } for (unsigned int i=0; iproject == p && !strcmp(name, app->name)) return app; @@ -342,6 +359,14 @@ APP* CLIENT_STATE::lookup_app(PROJECT* p, char* name) { } RESULT* CLIENT_STATE::lookup_result(PROJECT* p, char* name) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_result: unexpected NULL pointer p\n"); + return 0; + } + if(name==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_result: unexpected NULL pointer name\n"); + return 0; + } for (unsigned int i=0; iproject == p && !strcmp(name, rp->name)) return rp; @@ -350,6 +375,14 @@ RESULT* CLIENT_STATE::lookup_result(PROJECT* p, char* name) { } WORKUNIT* CLIENT_STATE::lookup_workunit(PROJECT* p, char* name) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_workunit: unexpected NULL pointer p\n"); + return 0; + } + if(name==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_workunit: unexpected NULL pointer name\n"); + return 0; + } for (unsigned int i=0; iproject == p && !strcmp(name, wup->name)) return wup; @@ -358,6 +391,14 @@ WORKUNIT* CLIENT_STATE::lookup_workunit(PROJECT* p, char* name) { } APP_VERSION* CLIENT_STATE::lookup_app_version(APP* app, int version_num) { + if(app==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_app_version: unexpected NULL pointer app\n"); + return 0; + } + if(version_num<0) { + fprintf(stderr, "error: CLIENT_STATE.lookup_app_version: negative version_num\n"); + return 0; + } for (unsigned int i=0; iapp == app && version_num==avp->version_num) { @@ -368,6 +409,14 @@ APP_VERSION* CLIENT_STATE::lookup_app_version(APP* app, int version_num) { } FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, char* name) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_file_info: unexpected NULL pointer p\n"); + return 0; + } + if(name==NULL) { + fprintf(stderr, "error: CLIENT_STATE.lookup_file_info: unexpected NULL pointer p\n"); + return 0; + } for (unsigned int i=0; iproject == p && !strcmp(fip->name, name)) { @@ -381,11 +430,27 @@ FILE_INFO* CLIENT_STATE::lookup_file_info(PROJECT* p, char* name) { // (which, in their XML form, reference one another by name) // int CLIENT_STATE::link_app(PROJECT* p, APP* app) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_app: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(app==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_app: unexpected NULL pointer app\n"); + return ERR_NULL; + } app->project = p; return 0; } int CLIENT_STATE::link_file_info(PROJECT* p, FILE_INFO* fip) { + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_file_info: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(fip==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_file_info: unexpected NULL pointer fip\n"); + return ERR_NULL; + } fip->project = p; return 0; } @@ -395,9 +460,15 @@ int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) { FILE_INFO* fip; FILE_REF file_ref; unsigned int i; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_app_version: unexpected NULL pointer fip\n"); + return ERR_NULL; + } + if(avp==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_app_version: unexpected NULL pointer fip\n"); + return ERR_NULL; + } avp->project = p; - app = lookup_app(p, avp->app_name); if (!app) { fprintf(stderr, @@ -428,7 +499,14 @@ int CLIENT_STATE::link_app_version(PROJECT* p, APP_VERSION* avp) { int CLIENT_STATE::link_file_ref(PROJECT* p, FILE_REF* file_refp) { FILE_INFO* fip; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_file_ref: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(file_refp==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_file_ref: unexpected NULL pointer file_refp\n"); + return ERR_NULL; + } fip = lookup_file_info(p, file_refp->file_name); if (!fip) { fprintf(stderr, @@ -445,7 +523,14 @@ int CLIENT_STATE::link_workunit(PROJECT* p, WORKUNIT* wup) { APP_VERSION* avp; unsigned int i; int retval; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_workunit: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(wup==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_workunit: unexpected NULL pointer wup\n"); + return ERR_NULL; + } app = lookup_app(p, wup->app_name); if (!app) { fprintf(stderr, @@ -474,7 +559,14 @@ int CLIENT_STATE::link_result(PROJECT* p, RESULT* rp) { WORKUNIT* wup; unsigned int i; int retval; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_result: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(rp==NULL) { + fprintf(stderr, "error: CLIENT_STATE.link_result: unexpected NULL pointer rp\n"); + return ERR_NULL; + } wup = lookup_workunit(p, rp->wu_name); if (!wup) { fprintf(stderr, "result refers to nonexistent WU: %s\n", rp->wu_name); @@ -608,6 +700,12 @@ int CLIENT_STATE::write_state_file_if_needed() { void CLIENT_STATE::parse_cmdline(int argc, char** argv) { int i; + if(argc<0) { + fprintf(stderr, "error: CLIENT_STATE.parse_cmdline: negative argc\n"); + } + if(argv==NULL) { + fprintf(stderr, "error: CLIENT_STATE.parse_cmdline: unexpected NULL pointer argv\n"); + } for (i=1; i", exp_avg_mod_time)) continue; else if (match_tag(buf, "")) { dup_element_contents(in, "", &code_sign_key); + //fprintf(stderr, "code_sign_key: %s\n", code_sign_key); } else fprintf(stderr, "PROJECT::parse_state(): unrecognized: %s\n", buf); } @@ -95,7 +102,10 @@ int PROJECT::parse_state(FILE* in) { int PROJECT::write_state(FILE* out) { unsigned int i; - + if(out==NULL) { + fprintf(stderr, "error: PROJECT.write_state: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" ); @@ -155,7 +165,10 @@ void PROJECT::copy_prefs_fields(PROJECT& p) { int APP::parse(FILE* in) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: APP.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(name, ""); project = NULL; while (fgets(buf, 256, in)) { @@ -168,6 +181,10 @@ int APP::parse(FILE* in) { } int APP::write(FILE* out) { + if(out==NULL) { + fprintf(stderr, "error: APP.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %s\n" @@ -191,7 +208,10 @@ FILE_INFO::~FILE_INFO() { int FILE_INFO::parse(FILE* in, bool from_server) { char buf[256]; STRING256 url; - + if(in==NULL) { + fprintf(stderr, "error: FILE_INFO.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(name, ""); strcpy(md5_cksum, ""); nbytes = 0; @@ -228,6 +248,7 @@ int FILE_INFO::parse(FILE* in, bool from_server) { } else if (match_tag(buf, "")) { dup_element_contents(in, "", &file_signature); + fprintf(stderr, "file_signature %s being copied\n", file_signature); continue; } else if (parse_str(buf, "", md5_cksum)) continue; @@ -251,6 +272,10 @@ int FILE_INFO::parse(FILE* in, bool from_server) { int FILE_INFO::write(FILE* out, bool to_server) { unsigned int i; + if(out==NULL) { + fprintf(stderr, "error: FILE_INFO.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %s\n" @@ -295,7 +320,10 @@ int FILE_INFO::delete_file() { int APP_VERSION::parse(FILE* in) { char buf[256]; FILE_REF file_ref; - + if(in==NULL) { + fprintf(stderr, "error: APP_VERSION.parse: unexpected NULL poiner in\n"); + return ERR_NULL; + } strcpy(app_name, ""); version_num = 0; app = NULL; @@ -316,6 +344,10 @@ int APP_VERSION::parse(FILE* in) { int APP_VERSION::write(FILE* out) { unsigned int i; + if(out==NULL) { + fprintf(stderr, "error: APP_VERSION.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %s\n" @@ -334,7 +366,10 @@ int APP_VERSION::write(FILE* out) { int FILE_REF::parse(FILE* in) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: FILE_REF.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(file_name, ""); strcpy(open_name, ""); fd = -1; @@ -351,6 +386,10 @@ int FILE_REF::parse(FILE* in) { } int FILE_REF::write(FILE* out) { + if(out==NULL) { + fprintf(stderr, "error: FILE_REF.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } if (strlen(open_name)) { fprintf(out, " %s\n", open_name); } @@ -372,7 +411,10 @@ int FILE_REF::write(FILE* out) { int WORKUNIT::parse(FILE* in) { char buf[256]; FILE_REF file_ref; - + if(in==NULL) { + fprintf(stderr, "error: WORKUNIT.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(name, ""); strcpy(app_name, ""); version_num = 0; @@ -401,6 +443,10 @@ int WORKUNIT::parse(FILE* in) { int WORKUNIT::write(FILE* out) { unsigned int i; + if(out==NULL) { + fprintf(stderr, "error: WORKUNIT.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %s\n" @@ -419,6 +465,10 @@ int WORKUNIT::write(FILE* out) { int RESULT::parse_ack(FILE* in) { char buf[256]; + if(in==NULL) { + fprintf(stderr, "error: RESULT.parse_ack: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(name, ""); while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; @@ -448,7 +498,10 @@ void RESULT::clear() { int RESULT::parse_server(FILE* in) { char buf[256]; FILE_REF file_ref; - + if(in==NULL) { + fprintf(stderr, "error: RESULT.parse_server: unexpected NULL pointer in\n"); + return ERR_NULL; + } while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", name)) continue; @@ -468,7 +521,10 @@ int RESULT::parse_server(FILE* in) { int RESULT::parse_state(FILE* in) { char buf[256]; FILE_REF file_ref; - + if(in==NULL) { + fprintf(stderr, "error: RESULT.parse_state: unexpected NULL pointer in\n"); + return ERR_NULL; + } while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; if (parse_str(buf, "", name)) continue; @@ -496,7 +552,10 @@ int RESULT::write(FILE* out, bool to_server) { unsigned int i; FILE_INFO* fip; int n; - + if(out==NULL) { + fprintf(stderr, "error: RESULT.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %s\n" diff --git a/client/cs_apps.C b/client/cs_apps.C index fa87c610ca..abb1e376f6 100644 --- a/client/cs_apps.C +++ b/client/cs_apps.C @@ -81,11 +81,14 @@ bool CLIENT_STATE::handle_running_apps() { } bool CLIENT_STATE::input_files_available(RESULT* rp) { + if(rp==NULL) { + fprintf(stderr, "error: CLIENT_STATE.input_files_available: unexpected NULL pointer rp\n"); + return false; + } WORKUNIT* wup = rp->wup; FILE_INFO* fip; unsigned int i; APP_VERSION* avp; - avp = wup->avp; for (i=0; iapp_files.size(); i++) { fip = avp->app_files[i].file_info; diff --git a/client/cs_files.C b/client/cs_files.C index 13034532f7..3e2d9cb2d8 100644 --- a/client/cs_files.C +++ b/client/cs_files.C @@ -37,6 +37,7 @@ #include "client_types.h" #include "log_flags.h" #include "client_state.h" +#include "error_numbers.h" int verify_downloaded_file(char* pathname, FILE_INFO& file_info) { char cksum[64]; @@ -44,13 +45,31 @@ int verify_downloaded_file(char* pathname, FILE_INFO& file_info) { bool verified; int retval; + if(pathname==NULL) { + fprintf(stderr, "error: verify_downloaded_file: unexpected NULL pointer pathname\n"); + return ERR_NULL; + } if (file_info.signature_required) { - if (!file_info.file_signature) return -1; + if (!file_info.file_signature) { + fprintf(stderr, "error: verify_downloaded_file: unexpected NULL pointer file_signature\n"); + return -1; + } project = file_info.project; retval = verify_file2( pathname, file_info.file_signature, project->code_sign_key, verified ); - if (retval || !verified) return -1; + if(retval) { + fprintf(stderr, "error: verify_file2: internal error\n"); + //return -1; + } + if(!verified) { + fprintf(stderr, "error: verify_file2: file not verified\n"); + //return -1; + } + if (retval || !verified) { + fprintf(stderr, "error: verify_file2: could not verify file\n"); + return -1; + } } else if (file_info.md5_cksum) { md5_file(pathname, cksum, file_info.nbytes); if (strcmp(cksum, file_info.md5_cksum)) return -1; diff --git a/client/cs_scheduler.C b/client/cs_scheduler.C index 81638826c7..de3e22b43c 100644 --- a/client/cs_scheduler.C +++ b/client/cs_scheduler.C @@ -35,7 +35,6 @@ #endif #include "crypt.h" - #include "error_numbers.h" #include "file_names.h" #include "parse.h" @@ -47,6 +46,7 @@ // quantities like avg CPU time decay by a factor of e every week #define EXP_DECAY_RATE (1./(3600*24*7)) +#define SECONDS_IN_DAY 86400 //estimates the number of days of work remaining // @@ -61,7 +61,7 @@ double CLIENT_STATE::current_water_days() { else seconds_remaining += rp->wup->seconds_to_complete; } - return (seconds_remaining * 86400); + return (seconds_remaining * SECONDS_IN_DAY); } bool CLIENT_STATE::need_work() { @@ -76,6 +76,9 @@ bool CLIENT_STATE::need_work() { void CLIENT_STATE::update_avg_cpu(PROJECT* p) { int now = time(0); + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.update_avg_cpu: unexpected NULL pointer p\n"); + } double deltat = now - p->exp_avg_mod_time; if (deltat > 0) { if (p->exp_avg_cpu != 0) { @@ -120,7 +123,14 @@ int CLIENT_STATE::make_scheduler_request(PROJECT* p, int work_req) { FILE* f = fopen(SCHED_OP_REQUEST_FILE, "wb"); unsigned int i; RESULT* rp; - + if(p==NULL) { + fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: unexpected NULL pointer p\n"); + return ERR_NULL; + } + if(work_req<0) { + fprintf(stderr, "error: CLIENT_STATE.make_scheduler_request: negative work_req\n"); + return ERR_NEG; + } if (!f) return ERR_FOPEN; fprintf(f, "\n" diff --git a/client/file_names.C b/client/file_names.C index 793939c4b2..422a626c64 100644 --- a/client/file_names.C +++ b/client/file_names.C @@ -28,6 +28,7 @@ #include #include "file_names.h" +#include "error_numbers.h" static void c2x(char *what) { char buf[3]; @@ -35,6 +36,9 @@ static void c2x(char *what) { char d1 = num / 16; char d2 = num % 16; int abase1, abase2; + if(what==NULL) { + fprintf(stderr, "error: c2x: unexpected NULL pointer what\n"); + } if (d1 < 10) abase1 = 48; else abase1 = 55; if (d2 < 10) abase2 = 48; @@ -48,6 +52,12 @@ static void c2x(char *what) { static void escape_url(char *in, char* out) { int x, y; + if(in==NULL) { + fprintf(stderr, "error: escape_url: unexpected NULL pointer in\n"); + } + if(out==NULL) { + fprintf(stderr, "error: escape_url: unexpected NULL pointer out\n"); + } for (x=0, y=0; in[x]; ++x) { if (isalnum(in[x])) { out[y] = in[x]; @@ -68,9 +78,14 @@ static void escape_url(char *in, char* out) { } void get_pathname(FILE_INFO* fip, char* path) { + if(fip==NULL) { + fprintf(stderr, "error: get_pathname: unexpected NULL pointer fip\n"); + } + if(path==NULL) { + fprintf(stderr, "error: get_pathname: unexpected NULL pointer path\n"); + } PROJECT* p = fip->project; char buf[256]; - // for testing purposes, it's handy to allow a FILE_INFO without // an associated PROJECT. // @@ -83,6 +98,12 @@ void get_pathname(FILE_INFO* fip, char* path) { } void get_slot_dir(int slot, char* path) { + if(path==NULL) { + fprintf(stderr, "error: get_slot_dir: unexpected NULL pointer path\n"); + } + if(slot<0) { + fprintf(stderr, "error: get_slot_dir: negative slot\n"); + } sprintf(path, "slots/%d", slot); } @@ -99,6 +120,10 @@ int make_project_dir(PROJECT& p) { } int make_slot_dir(int slot) { + if(slot<0) { + fprintf(stderr, "error: make_slot_dir: negative slot\n"); + return ERR_NEG; + } char buf[256]; CreateDirectory("slots", NULL); get_slot_dir(slot, buf); @@ -118,6 +143,10 @@ int make_project_dir(PROJECT& p) { int make_slot_dir(int slot) { char buf[256]; + if(slot<0) { + fprintf(stderr, "error: make_slot_dir: negative slot\n"); + return ERR_NEG; + } mkdir("slots", 0777); get_slot_dir(slot, buf); mkdir(buf, 0777); @@ -125,6 +154,10 @@ int make_slot_dir(int slot) { } int make_prefs_backup_name(PREFS& prefs, char* name) { + if(name==NULL) { + fprintf(stderr, "error: make_prefs_backup_name: unexpected NULL pointer name\n"); + return ERR_NULL; + } sprintf(name, "prefs_backup_%d", prefs.mod_time); return 0; } diff --git a/client/file_xfer.C b/client/file_xfer.C index 5c3c551326..691c9e5dfd 100644 --- a/client/file_xfer.C +++ b/client/file_xfer.C @@ -23,6 +23,7 @@ #include "file_names.h" #include "log_flags.h" #include "file_xfer.h" +#include "error_numbers.h" FILE_XFER::FILE_XFER() { file_xfer_done = false; @@ -34,10 +35,26 @@ FILE_XFER::~FILE_XFER() { #if 0 int FILE_XFER::init_download(char* url, char* outfile) { + if(url==NULL) { + fprintf(stderr, "error: FILE_XFER.init_download: unexpected NULL pointer url\n"); + return ERR_NULL; + } + if(outfile==NULL) { + fprintf(stderr, "error: FILE_XFER.init_download: unexpected NULL pointer outfile\n"); + return ERR_NULL; + } return HTTP_OP::init_get(url, outfile); } int FILE_XFER::init_upload(char* url, char* infile) { + if(url==NULL) { + fprintf(stderr, "error: FILE_XFER.init_upload: unexpected NULL pointer url\n"); + return ERR_NULL; + } + if(outfile==NULL) { + fprintf(stderr, "error: FILE_XFER.init_upload: unexpected NULL pointer infile\n"); + return ERR_NULL; + } return HTTP_OP::init_put(url, infile); } #endif @@ -77,12 +94,18 @@ double FILE_XFER::elapsed_time() { } FILE_XFER_SET::FILE_XFER_SET(HTTP_OP_SET* p) { + if(p==NULL) { + fprintf(stderr, "error: FILE_XFER_SET: unexpected NULL pointer p\n"); + } http_ops = p; } int FILE_XFER_SET::insert(FILE_XFER* fxp) { int retval; - + if(fxp==NULL) { + fprintf(stderr, "error: FILE_XFER_SET.insert: unexpected NULL pointer fxp\n"); + return ERR_NULL; + } // record start time. // This could be made more accurate by omitting the connection // setup and initial request times. @@ -96,7 +119,10 @@ int FILE_XFER_SET::insert(FILE_XFER* fxp) { int FILE_XFER_SET::remove(FILE_XFER* fxp) { vector::iterator iter; - + if(fxp==NULL) { + fprintf(stderr, "error: FILE_XFER_SET.remove: unexpected NULL pointer fxp\n"); + return ERR_NULL; + } http_ops->remove(fxp); iter = file_xfers.begin(); diff --git a/client/filesys.C b/client/filesys.C index cd444ef0fc..9b091c4d32 100644 --- a/client/filesys.C +++ b/client/filesys.C @@ -74,6 +74,10 @@ char failed_file[256]; // routines for enumerating the entries in a directory int dir_open(char* p) { + if(p==NULL) { + fprintf(stderr, "error: dir_open: unexpected NULL pointer p\n"); + return ERR_NULL; + } #ifdef HAVE_DIRENT_H dirp = opendir(p); if (!dirp) return ERR_OPENDIR; @@ -91,6 +95,10 @@ int dir_open(char* p) { } int dir_scan(char* p) { + if(p==NULL) { + fprintf(stderr, "error: dir_scan: unexpected NULL pointer p\n"); + return ERR_NULL; + } #ifdef HAVE_DIRENT_H while (1) { dirent* dp = readdir(dirp); @@ -157,7 +165,10 @@ void dir_close() { int file_delete(char* path) { int retval,i; - + if(path==NULL) { + fprintf(stderr, "error: file_delete: unexpected NULL pointer path\n"); + return ERR_NULL; + } for (i=0; i<2; i++) { #ifdef HAVE_UNISTD_H retval = unlink(path); @@ -179,7 +190,10 @@ int file_delete(char* path) { int file_size(char* path, int& size) { struct stat sbuf; int retval; - + if(path==NULL) { + fprintf(stderr, "error: file_size: unexpected NULL pointer path\n"); + return ERR_NULL; + } retval = stat(path, &sbuf); if (retval) return retval; size = sbuf.st_size; @@ -191,20 +205,30 @@ int file_size(char* path, int& size) { int boinc_link( char *existing, char *new_link ) { FILE *fp; + if(existing==NULL) { + fprintf(stderr, "error: boinc_link: unexpected NULL pointer existing\n"); + return ERR_NULL; + } + if(new_link==NULL) { + fprintf(stderr, "error: boinc_link: unexpected NULL pointer new_link\n"); + return ERR_NULL; + } + fp = fopen( new_link, "wb" ); + if (!fp) return ERR_FOPEN; + rewind( fp ); + fprintf( fp, "%s\n", existing ); + fclose( fp ); - fp = fopen( new_link, "wb" ); - if (!fp) return ERR_FOPEN; - rewind( fp ); - fprintf( fp, "%s\n", existing ); - fclose( fp ); - - return 0; + return 0; } int clean_out_dir(char* dirpath) { char filename[256], path[256]; int retval; - + if(dirpath==NULL) { + fprintf(stderr, "error: clean_out_dir: unexpected NULL pointer dirpath\n"); + return ERR_NULL; + } retval = dir_open(dirpath); if (retval) return retval; while (1) { diff --git a/client/hostinfo.C b/client/hostinfo.C index 59ea320482..0b97f0ae63 100644 --- a/client/hostinfo.C +++ b/client/hostinfo.C @@ -22,10 +22,14 @@ #include "parse.h" #include "hostinfo.h" +#include "error_numbers.h" int HOST_INFO::parse(FILE* in) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: HOST_INFO.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } memset(this, 0, sizeof(HOST_INFO)); while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; @@ -52,6 +56,10 @@ int HOST_INFO::parse(FILE* in) { } int HOST_INFO::write(FILE* out) { + if(out==NULL) { + fprintf(stderr, "error: HOST_INFO.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %d\n" diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index 16f3984125..3b6537567a 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -57,12 +57,16 @@ #endif #include "client_types.h" +#include "error_numbers.h" // functions to get name/addr of local host int get_local_domain_name(char* p) { char buf[256]; - + if(p==NULL) { + fprintf(stderr, "error: get_local_domain_name: unexpected NULL pointer p\n"); + return ERR_NULL; + } gethostname(buf, 256); struct hostent* he = gethostbyname(buf); strcpy(p, he->h_name); @@ -83,6 +87,10 @@ int get_local_ip_addr(int& p) { int get_local_ip_addr_str(char* p) { char buf[256]; + if(p==NULL) { + fprintf(stderr, "error: get_local_ip_addr_str: unexpected NULL pointer p\n"); + return ERR_NULL; + } #if HAVE_NETDB_H struct in_addr addr; gethostname(buf, 256); @@ -227,10 +235,10 @@ int get_host_info(HOST_INFO& host) { #endif get_local_domain_name(host.domain_name); get_local_ip_addr_str(host.ip_addr); + get_timezone(host.timezone); #ifdef HAVE_SYS_UTSNAME_H get_osinfo(host); #endif - get_timezone(host.timezone); return 0; } diff --git a/client/http.C b/client/http.C index aa540bd95b..b6e0d0dd88 100644 --- a/client/http.C +++ b/client/http.C @@ -39,7 +39,15 @@ static void parse_url(char* url, char* host, char* file) { char* p; char buf[256]; - + if(url==NULL) { + fprintf(stderr, "error: parse_url: unexpected NULL pointer url\n"); + } + if(host==NULL) { + fprintf(stderr, "error: parse_url: unexpected NULL pointer host\n"); + } + if(file==NULL) { + fprintf(stderr, "error: parse_url: unexpected NULL pointer file\n"); + } if (strncmp(url, "http://", 7) == 0) strcpy(buf, url+7); else strcpy(buf, url); p = strchr(buf, '/'); @@ -59,6 +67,18 @@ static void parse_url(char* url, char* host, char* file) { static void http_get_request_header( char* buf, char* host, char* file, int offset ) { + if(buf==NULL) { + fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer buf\n"); + } + if(host==NULL) { + fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer host\n"); + } + if(file==NULL) { + fprintf(stderr, "error: http_get_request_header: unexpected NULL pointer file\n"); + } + if(offset<0) { + fprintf(stderr, "error: http_get_request_header: negative offset\n"); + } if (offset) { sprintf(buf, "GET /%s;byte-range %d- HTTP/1.0\015\012" @@ -83,6 +103,15 @@ static void http_get_request_header( } static void http_head_request_header(char* buf, char* host, char* file) { + if(buf==NULL) { + fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer buf\n"); + } + if(host==NULL) { + fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer host\n"); + } + if(file==NULL) { + fprintf(stderr, "error: http_head_request_header: unexpected NULL pointer file\n"); + } sprintf(buf, "HEAD /%s HTTP/1.0\015\012" "User-Agent: BOINC client\015\012" @@ -96,6 +125,18 @@ static void http_head_request_header(char* buf, char* host, char* file) { static void http_post_request_header( char* buf, char* host, char* file, int size ) { + if(buf==NULL) { + fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer buf\n"); + } + if(host==NULL) { + fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer host\n"); + } + if(file==NULL) { + fprintf(stderr, "error: http_post_request_header: unexpected NULL pointer file\n"); + } + if(size<0) { + fprintf(stderr, "error: http_post_request_header: negative size\n"); + } sprintf(buf, "POST /%s HTTP/1.0\015\012" "Pragma: no-cache\015\012" @@ -112,6 +153,21 @@ static void http_post_request_header( void http_put_request_header( char* buf, char* host, char* file, int size, int offset ) { + if(buf==NULL) { + fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer buf\n"); + } + if(host==NULL) { + fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer host\n"); + } + if(file==NULL) { + fprintf(stderr, "error: http_put_request_header: unexpected NULL pointer file\n"); + } + if(size<0) { + fprintf(stderr, "error: http_put_request_header: negative size\n"); + } + if(offset<0) { + fprintf(stderr, "error: http_put_request_header: negative offset\n"); + } if (offset) { sprintf(buf, "PUT /%s;byte-range %d- HTTP/1.0\015\012" @@ -143,7 +199,10 @@ void http_put_request_header( int read_http_reply_header(int socket, HTTP_REPLY_HEADER& header) { int i, n; char buf[1024], *p; - + if(socket<0) { + fprintf(stderr, "error: read_http_reply_header: negative socket\n"); + return ERR_NEG; + } memset(buf, 0, sizeof(buf)); header.content_length = 0; header.status = 404; // default to failure @@ -167,6 +226,18 @@ int read_http_reply_header(int socket, HTTP_REPLY_HEADER& header) { static int read_reply(int socket, char* buf, int len) { int i, n; + if(socket<0) { + fprintf(stderr, "error: read_reply: negative socket\n"); + return ERR_NEG; + } + if(buf==NULL) { + fprintf(stderr, "error: read_reply: unexpected NULL pointer buf\n"); + return ERR_NULL; + } + if(len<0) { + fprintf(stderr, "error: read_reply: negative len\n"); + return ERR_NEG; + } for (i=0; iinsert(ho); if (retval) return retval; http_ops.push_back(ho); @@ -429,7 +549,10 @@ bool HTTP_OP_SET::poll() { int HTTP_OP_SET::remove(HTTP_OP* p) { vector::iterator iter; - + if(p==NULL) { + fprintf(stderr, "error: HTTP_OP_SET.remove: unexpected NULL pointer p\n"); + return ERR_NULL; + } net_xfers->remove(p); iter = http_ops.begin(); diff --git a/client/log_flags.C b/client/log_flags.C index 5583b69926..0ffb270c81 100644 --- a/client/log_flags.C +++ b/client/log_flags.C @@ -33,7 +33,10 @@ LOG_FLAGS::LOG_FLAGS() { int LOG_FLAGS::parse(FILE* in) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: LOG_FLAGS.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } fgets(buf, 256, in); if (!match_tag(buf, "")) return ERR_XML_PARSE; while (fgets(buf, 256, in)) { diff --git a/client/main.C b/client/main.C index 9444e3a4af..3599cf5990 100644 --- a/client/main.C +++ b/client/main.C @@ -31,6 +31,12 @@ #include "util.h" void show_message(char* message, char* priority) { + if(message==NULL) { + fprintf(stderr, "error: show_message: unexpected NULL pointer message\n"); + } + if(priority==NULL) { + fprintf(stderr, "error: show_message: unexpected NULL pointer priority\n"); + } if (!strcmp(priority, "high")) { fprintf(stderr, "BOINC core client: %s\n", message); } else { diff --git a/client/net_stats.C b/client/net_stats.C index 9b8931ad1d..bcf73f7c4a 100644 --- a/client/net_stats.C +++ b/client/net_stats.C @@ -23,6 +23,7 @@ #include "parse.h" #include "time.h" +#include "error_numbers.h" #include "net_stats.h" #define SMALL_FILE_CUTOFF 32000 @@ -66,6 +67,10 @@ void NET_STATS::update(bool is_upload, double nbytes, double nsecs) { } int NET_STATS::write(FILE* out, bool to_server) { + if(out==NULL) { + fprintf(stderr, "error: NET_STATS.write: unexpected NULL pointer out\n"); + return ERR_NULL; + } fprintf(out, "\n" " %f\n" @@ -86,7 +91,10 @@ int NET_STATS::write(FILE* out, bool to_server) { int NET_STATS::parse(FILE* in) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: NET_STATS.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } memset(this, 0, sizeof(NET_STATS)); while (fgets(buf, 256, in)) { if (match_tag(buf, "")) return 0; diff --git a/client/scheduler_op.C b/client/scheduler_op.C index 7e3e94b893..84cc5db25d 100644 --- a/client/scheduler_op.C +++ b/client/scheduler_op.C @@ -27,6 +27,9 @@ #include "scheduler_op.h" SCHEDULER_OP::SCHEDULER_OP(HTTP_OP_SET* h) { + if(h==NULL) { + fprintf(stderr, "error: SCHEDULER_OP: unexpected NULL pointer h\n"); + } state = SCHEDULER_OP_STATE_IDLE; http_op.http_op_state = HTTP_STATE_IDLE; http_ops = h; @@ -59,6 +62,10 @@ int SCHEDULER_OP::start_rpc() { } int SCHEDULER_OP::start_op(PROJECT* p) { + if(p==NULL) { + fprintf(stderr, "error: SCHEDULER_OP.start_op: unexpected NULL pointer p\n"); + return ERR_NULL; + } project = p; if (project->scheduler_urls.size() == 0) { http_op.init_get(project->master_url, MASTER_FILE_NAME); @@ -143,7 +150,10 @@ SCHEDULER_REPLY::~SCHEDULER_REPLY() { int SCHEDULER_REPLY::parse(FILE* in) { char buf[256]; int retval; - + if(in==NULL) { + fprintf(stderr, "error: SCHEDULER_REPLY.parse: unexpected NULL pointer in\n"); + return ERR_NULL; + } strcpy(message, ""); strcpy(message_priority, ""); request_delay = 0; @@ -172,7 +182,11 @@ int SCHEDULER_REPLY::parse(FILE* in) { if (retval) return ERR_XML_PARSE; } else if (match_tag(buf, "")) { retval = dup_element_contents(in, "", &code_sign_key); - if (retval) return ERR_XML_PARSE; + //fprintf(stderr, "code_sign_key: %s\n", code_sign_key); + if (retval) { + fprintf(stderr, "error: SCHEDULER_REPLY.parse: xml parsing error\n"); + return ERR_XML_PARSE; + } } else if (match_tag(buf, "")) { retval = dup_element_contents(in, "", &code_sign_key_signature); if (retval) return ERR_XML_PARSE; diff --git a/client/speed_stats.C b/client/speed_stats.C index c7d3ef5288..cdb98f3dfd 100644 --- a/client/speed_stats.C +++ b/client/speed_stats.C @@ -4,6 +4,7 @@ #include #include "speed_stats.h" +#include "error_numbers.h" #define D_FLOP_ITERS 1 #define I_OP_ITERS 1 @@ -32,7 +33,10 @@ int check_cache_size( int mem_size ) { clock_t total_sec, sec; double secs, nanosecs, temp2; int not_found; - + if(mem_size<0) { + fprintf(stderr, "error: check_cache_size: negative mem_size\n"); + return ERR_NEG; + } logStride = (int)(log(STRIDE_MAX/STRIDE_MIN)/log(2))+1; logCache = (int)(log(CACHE_MAX/CACHE_MIN)/log(2))+1; @@ -162,7 +166,10 @@ int check_cache_size( int mem_size ) { double run_double_prec_test( double num_secs ) { int df_test_time, df_iters; double df_secs; - + if(num_secs<0) { + fprintf(stderr, "error: run_double_prec_test: negatvie num_secs\n"); + return ERR_NEG; + } // Start by doing some quick timing tests for rough calibration df_test_time = (int)double_flop_test( D_FLOP_ITERS, 0 ); if( df_test_time <= 0 ) df_test_time = 1; @@ -185,7 +192,10 @@ double run_double_prec_test( double num_secs ) { double run_int_test( double num_secs ) { int int_test_time, int_iters; double int_secs; - + if(num_secs<0) { + fprintf(stderr, "error: run_int_test: negative num_secs\n"); + return ERR_NEG; + } // Start by doing some quick timing tests for rough calibration int_test_time = (int)int_op_test( I_OP_ITERS, 0 ); if( int_test_time <= 0 ) int_test_time = 1; @@ -209,7 +219,10 @@ double run_mem_bandwidth_test( double num_secs ) { int bw_test_time; double bw_secs; int bw_iters; - + if(num_secs<0) { + fprintf(stderr, "error: run_mem_bandwidth_test: negative num_secs\n"); + return ERR_NEG; + } // Start by doing some quick timing tests for rough calibration bw_test_time = (int)bandwidth_test( BANDWIDTH_ITERS, 0 ); if( bw_test_time <= 0 ) bw_test_time = 1; @@ -229,6 +242,9 @@ double run_mem_bandwidth_test( double num_secs ) { } void run_test_suite( double num_secs_per_test ) { + if(num_secs_per_test<0) { + fprintf(stderr, "error: run_test_suite: negative num_seconds_per_test\n"); + } printf( "Running tests. This will take about %.1lf seconds.\n\n", num_secs_per_test*3 @@ -255,7 +271,10 @@ clock_t double_flop_test( int iterations, int print_debug ) { double temp; clock_t time_start, time_total; int i,j,k,calc_error; - + if(iterations<0) { + fprintf(stderr, "error: double_flop_test: negative iterations\n"); + return ERR_NEG; + } // Initialize the array a[0] = 1; for( i=1;i")) return 0; else if (parse_int(buf, "", last_update)) continue; diff --git a/client/util.C b/client/util.C index fe2a103f04..22217aa363 100644 --- a/client/util.C +++ b/client/util.C @@ -16,6 +16,7 @@ // // Contributor(s): // +#include #ifndef _WIN32 #include @@ -24,11 +25,19 @@ #include #include +#include "error_numbers.h" + /* Replacement gettimeofday Sets the microseconds to clock() * 1000 which is microseconds in Windows */ void gettimeofday(timeval *t, void *tz) { - t->tv_sec = time(NULL); - t->tv_usec = 1000 * (long)(clock()); + if(t==NULL) { + fprintf(stderr, "error: gettimeofday: unexpected NULL pointer t\n"); + } + if(tz==NULL) { + fprintf(stderr, "error: gettimeofday: unexpected NULL pointer tz\n"); + } + t->tv_sec = time(NULL); + t->tv_usec = 1000 * (long)(clock()); } #endif @@ -45,13 +54,21 @@ double dtime() { #ifdef _WIN32 void boinc_sleep( int seconds ) { - ::Sleep( 1000*seconds ); + if(seconds<0) { + fprintf(stderr, "error: boinc_sleep: negative seconds\n"); + seconds=0; + } + ::Sleep( 1000*seconds ); } #else void boinc_sleep( int seconds ) { - sleep( seconds ); + if(seconds<0) { + fprintf(stderr,"error: boinc_sleep: negative seconds\n"); + seconds=0; + } + sleep( seconds ); } #endif diff --git a/configure b/configure index 3881f429bb..e383775c80 100755 --- a/configure +++ b/configure @@ -1386,7 +1386,7 @@ EOF fi -for ac_hdr in fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h +for ac_hdr in fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h signal.h sys/wait.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 diff --git a/configure.in b/configure.in index 02f1f82e88..5dd33d4af4 100644 --- a/configure.in +++ b/configure.in @@ -23,7 +23,7 @@ dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_HEADER_SYS_WAIT -AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h) +AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h sys/systeminfo.h sys/resource.h sys/types.h dirent.h sys/utsname.h netdb.h netinet/in.h arpa/inet.h signal.h sys/wait.h) AC_CHECK_HEADERS(mysql/include/mysql_com.h mysql/mysql_com.h) dnl Checks for typedefs, structures, and compiler characteristics. diff --git a/db/db_mysql.C b/db/db_mysql.C index b760cdcdb9..dfe625ac19 100644 --- a/db/db_mysql.C +++ b/db/db_mysql.C @@ -20,6 +20,7 @@ #include #include #include +#include #include "mysql_util.h" @@ -52,7 +53,8 @@ void struct_to_str(void* vp, char* q, int type) { HOST* hp; WORKUNIT* wup; RESULT* rp; - + assert(vp!=NULL); + assert(q!=NULL); switch(type) { case TYPE_PLATFORM: pp = (PLATFORM*)vp; @@ -198,7 +200,7 @@ void row_to_struct(MYSQL_ROW& r, void* vp, int type) { RESULT* rp; int i=0; - + assert(vp!=NULL); switch(type) { case TYPE_PLATFORM: pp = (PLATFORM*)vp; @@ -381,7 +383,7 @@ int db_app_version_lookup( int appid, int platformid, int version_num, APP_VERSION& p ) { char buf[256]; - + assert(version_num>=0); sprintf(buf, "appid=%d and platformid=%d and version_num=%d", appid, platformid, version_num diff --git a/db/mysql_util.C b/db/mysql_util.C index f543ea6bea..1ba6571878 100644 --- a/db/mysql_util.C +++ b/db/mysql_util.C @@ -24,6 +24,7 @@ #include #include #include +#include #include "mysql.h" #include "mysql_util.h" @@ -39,6 +40,7 @@ static MYSQL_ROW row; #define MAX_QUERY_LEN 8192 int db_open(char* name) { + //assert(name!=NULL); mp = mysql_init(0); if (!mp) return -1; mp = mysql_real_connect(mp, 0, 0, "", name, 0, 0, 0); @@ -52,6 +54,7 @@ int db_close() { } void db_print_error(char* p) { + assert(p!=NULL); if (mp) { printf("
%s: Database error: %s\n", p, mysql_error(mp)); } @@ -59,6 +62,7 @@ void db_print_error(char* p) { // convert ' to \' in place void escape(char* field) { + assert(field!=NULL); char buf[MAX_QUERY_LEN]; char* q = buf, *p = field; while (*p) { @@ -76,6 +80,7 @@ void escape(char* field) { void unescape(char* p) { char* q; + assert(p!=NULL); while (1) { q = strstr(p, "\\'"); if (!q) break; @@ -85,11 +90,13 @@ void unescape(char* p) { // assumes ID is first static int* id(void* vp, int type) { + assert(vp!=NULL); return (int*) vp; } int db_new(void* vp, int type) { char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN]; + assert(vp!=NULL); struct_to_str(vp, sbuf, type); sprintf(buf, "insert into %s set %s", table_name[type], sbuf); return mysql_query(mp, buf); @@ -111,6 +118,7 @@ int db_delete(int id, int type) { int db_lookup_id(int i, void* vp, int type) { char buf[MAX_QUERY_LEN]; + assert(vp!=NULL); sprintf(buf, "select * from %s where id=%d", table_name[type], i); mysql_query(mp, buf); rp = mysql_store_result(mp); @@ -123,6 +131,8 @@ int db_lookup_id(int i, void* vp, int type) { int db_lookup(void* vp, int type, char* clause) { char buf[MAX_QUERY_LEN]; + assert(vp!=NULL); + assert(clause!=NULL); sprintf(buf, "select * from %s where %s", table_name[type], clause); mysql_query(mp, buf); rp = mysql_store_result(mp); @@ -135,6 +145,7 @@ int db_lookup(void* vp, int type, char* clause) { int db_update(void* vp, int type) { char buf[MAX_QUERY_LEN], sbuf[MAX_QUERY_LEN]; + assert(vp!=NULL); struct_to_str(vp, sbuf, type); sprintf( buf, @@ -145,7 +156,9 @@ int db_update(void* vp, int type) { } int db_enum(ENUM& e, void* p, int type, char* clause, int limit) { - char buf[MAX_QUERY_LEN], buf2[256];; + char buf[MAX_QUERY_LEN], buf2[256]; + //assert(p!=NULL); + //assert(clause!=NULL); if (!e.active) { e.active = 1; sprintf(buf, "select * from %s %s", table_name[type], clause?clause:""); @@ -170,6 +183,8 @@ int db_enum(ENUM& e, void* p, int type, char* clause, int limit) { int db_enum_field(ENUM& e, int type, char* field, char* clause) { char buf[MAX_QUERY_LEN]; + assert(field!=NULL); + assert(clause!=NULL); if (!e.active) { e.active = 1; sprintf(buf, "select %s from %s %s", field, table_name[type], clause); @@ -188,6 +203,8 @@ int db_enum_field(ENUM& e, int type, char* field, char* clause) { } int db_query_int(int* ip, char* query) { + assert(ip!=NULL); + assert(query!=NULL); mysql_query(mp, query); rp = mysql_store_result(mp); if (!rp) return -1; @@ -200,6 +217,9 @@ int db_query_int(int* ip, char* query) { int db_count(int* np, char* what, int type, char* clause) { char buf[MAX_QUERY_LEN]; + assert(np!=NULL); + assert(what!=NULL); + assert(clause!=NULL); sprintf(buf, "select count(%s) from %s %s", what, table_name[type], clause); return db_query_int(np, buf); } diff --git a/lib/crypt.C b/lib/crypt.C index ef376a2c18..573d98a072 100644 --- a/lib/crypt.C +++ b/lib/crypt.C @@ -3,6 +3,7 @@ #include "md5_file.h" #include "crypt.h" +#include "error_numbers.h" // NOTE: the fast CGI I/O library doesn't have fscanf(), // so some of the following have been modified to use @@ -13,22 +14,29 @@ // we follow the data with a non-hex character '.' // int print_hex_data(FILE* f, DATA_BLOCK& x) { - int i; - + unsigned int i; + if(f==NULL) { + fprintf(stderr, "error: print_hex_data: unexpected NULL pointer f\n"); + return ERR_NULL; + } for (i=0; ibits); len = size - sizeof(key->bits); x.data = key->data; @@ -106,9 +138,21 @@ int print_key_hex(FILE* f, KEY* key, int size) { int scan_key_hex(FILE* f, KEY* key, int size) { int len, i, n; int num_bits; - + if(f==NULL) { + fprintf(stderr, "error: scan_key_hex: unexpected NULL pointer f\n"); + return ERR_NULL; + } + if(key==NULL) { + fprintf(stderr, "error: scan_key_hex: unexpected NULL pointer key\n"); + return ERR_NULL; + } + if(size<=0) { + fprintf(stderr, "error: scan_key_hex: size = %d\n", size); + return ERR_NEG; + } #if _USING_FCGI_ - char buf[256]; +#if 0 + char *p, buf[256]; int j = 0, b; fgets(buf, 256, f); sscanf(buf, "%d", &num_bits); @@ -127,6 +171,7 @@ int scan_key_hex(FILE* f, KEY* key, int size) { } fgets(buf, size, f); sscanf(buf, "."); +#endif #else fscanf(f, "%d", &num_bits); key->bits = num_bits; @@ -143,16 +188,30 @@ int scan_key_hex(FILE* f, KEY* key, int size) { // parse a text-encoded key from a memory buffer // int sscan_key_hex(char* buf, KEY* key, int size) { - int n, retval; + int n, retval,num_bits; DATA_BLOCK db; - - n = sscanf(buf, "%d", &key->bits); + if(buf==NULL) { + fprintf(stderr, "error: sscan_key_hex: unexpected NULL pointer buf\n"); + return ERR_NULL; + } + if(key==NULL) { + fprintf(stderr, "error: sscan_key_hex: unexpected NULL pointer key\n"); + return ERR_NULL; + } + if(size<=0) { + fprintf(stderr, "error: sscan_key_hex: size = %d\n", size); + return ERR_NEG; + } + //fprintf(stderr, "buf = %s\n", buf); + n = sscanf(buf, "%d", &num_bits); + key->bits = num_bits; //key->bits is a short + //fprintf(stderr, "key->bits = %d\n", key->bits); if (n != 1) return -1; buf = strchr(buf, '\n'); if (!buf) return -1; buf += 1; db.data = key->data; - db.len = size - sizeof(key->bits); + db.len = size - sizeof(key->bits); //huh??? retval = sscan_hex_data(buf, db); return retval; } @@ -179,6 +238,10 @@ int encrypt_private( } int decrypt_public(R_RSA_PUBLIC_KEY& key, DATA_BLOCK& in, DATA_BLOCK& out) { + if(key.bits<=0) { + fprintf(stderr, "error: decrypt_public: key.bits = %d\n", key.bits); + return ERR_NEG; + } return RSAPublicDecrypt(out.data, &out.len, in.data, in.len, &key); } @@ -187,7 +250,10 @@ int sign_file(char* path, R_RSA_PRIVATE_KEY& key, DATA_BLOCK& signature) { double file_length; DATA_BLOCK in_block; int retval, n; - + if(path==NULL) { + fprintf(stderr, "error: sign_file: unexpected NULL pointer path\n"); + return ERR_NULL; + } retval = md5_file(path, md5_buf, file_length); if (retval) return retval; in_block.data = (unsigned char*)md5_buf; @@ -220,14 +286,23 @@ int verify_file( double file_length; int n, retval; DATA_BLOCK clear_signature; - + if(path==NULL) { + fprintf(stderr, "error: verify_file: unexpected NULL pointer path\n"); + return ERR_NULL; + } retval = md5_file(path, md5_buf, file_length); - if (retval) return retval; + if (retval) { + fprintf(stderr, "error: verify_file: md5_file error %d\n", retval); + return retval; + } n = strlen(md5_buf); clear_signature.data = (unsigned char*)clear_buf; clear_signature.len = MD5_LEN; retval = decrypt_public(key, signature, clear_signature); - if (retval) return retval; + if (retval) { + fprintf(stderr, "error: verify_file: decrypt_public error %d\n", retval); + return retval; + } answer = !strncmp(md5_buf, clear_buf, n); return 0; } @@ -239,9 +314,23 @@ int verify_file2( unsigned char signature_buf[SIGNATURE_SIZE_BINARY]; int retval; DATA_BLOCK signature; - + if(path==NULL) { + fprintf(stderr, "error: verify_file2: unexpected NULL pointer path\n"); + return ERR_NULL; + } + if(signature_text==NULL) { + fprintf(stderr, "error: verify_file2: unexpected NULL pointer signature_text\n"); + return ERR_NULL; + } + if(key_text==NULL) { + fprintf(stderr, "error: verify_file2: unexpected NULL pointer key_text\n"); + return ERR_NULL; + } retval = sscan_key_hex(key_text, (KEY*)&key, sizeof(key)); - if (retval) return retval; + if (retval) { + fprintf(stderr, "error: verify_file2: sscan_key_hex did not work\n"); + return retval; + } signature.data = signature_buf; signature.len = sizeof(signature_buf); sscan_hex_data(signature_text, signature); @@ -258,7 +347,14 @@ int verify_string( char clear_buf[MD5_LEN]; int retval, n; DATA_BLOCK signature, clear_signature; - + if(text==NULL) { + fprintf(stderr, "error: verify_string: unexpected NULL pointer text\n"); + return ERR_NULL; + } + if(signature_text==NULL) { + fprintf(stderr, "error: verify_string: unexpected NULL pointer signature_text\n"); + return ERR_NULL; + } retval = md5_block((unsigned char*)text, strlen(text), md5_buf); if (retval) return retval; n = strlen(md5_buf); diff --git a/client/error_numbers.h b/lib/error_numbers.h old mode 100644 new mode 100755 similarity index 92% rename from client/error_numbers.h rename to lib/error_numbers.h index 9e6a4c4c8e..2e60f337f3 --- a/client/error_numbers.h +++ b/lib/error_numbers.h @@ -33,3 +33,7 @@ #define ERR_GETHOSTBYNAME -113 #define ERR_GIVEUP -114 // too much time has elapsed without progress on file xfer +#define ERR_NULL -115 + // unexpected NULL pointer +#define ERR_NEG -116 + // unexpected negative value diff --git a/lib/md5_file.C b/lib/md5_file.C index 2a01773552..7aca9a2ca6 100644 --- a/lib/md5_file.C +++ b/lib/md5_file.C @@ -2,6 +2,7 @@ #include "md5.h" #include "md5_file.h" +#include "error_numbers.h" int md5_file(char* path, char* output, double& nbytes) { unsigned char buf[4096]; @@ -9,7 +10,14 @@ int md5_file(char* path, char* output, double& nbytes) { FILE* f; md5_state_t state; int i, n; - + if(path==NULL) { + fprintf(stderr, "error: md5_file: unexpected NULL pointer path\n"); + return ERR_NULL; + } + if(output==NULL) { + fprintf(stderr, "error: md5_file: unexpected NULL pointer output\n"); + return ERR_NULL; + } nbytes = 0; f = fopen(path, "rb"); if (!f) { @@ -36,7 +44,18 @@ int md5_file(char* path, char* output, double& nbytes) { int md5_block(unsigned char* data, int nbytes, char* output) { unsigned char binout[16]; int i; - + if(data==NULL) { + fprintf(stderr, "error: md5_block: unexpected NULL pointer data\n"); + return ERR_NULL; + } + if(nbytes<0) { + fprintf(stderr, "error: md5_block: negative nbytes\n"); + return ERR_NEG; + } + if(output==NULL) { + fprintf(stderr, "error: md5_block: unexpected NULL pointer output\n"); + return ERR_NULL; + } md5_state_t state; md5_init(&state); md5_append(&state, data, nbytes); diff --git a/lib/parse.C b/lib/parse.C index 7c07411326..da409bd685 100644 --- a/lib/parse.C +++ b/lib/parse.C @@ -32,13 +32,30 @@ #include #include "parse.h" +#include "error_numbers.h" bool match_tag(char* buf, char* tag) { + if(buf==NULL) { + fprintf(stderr, "error: match_tag: unexpected NULL pointer buf\n"); + return false; + } + if(tag==NULL) { + fprintf(stderr, "error: match_tag: unexpected NULL pointer tag\n"); + return false; + } if (strstr(buf, tag)) return true; return false; } bool parse_int(char* buf, char* tag, int& x) { + if(buf==NULL) { + fprintf(stderr, "error: parse_int: unexpected NULL pointer buf\n"); + return false; + } + if(tag==NULL) { + fprintf(stderr, "error: parse_int: unexpected NULL pointer tag\n"); + return false; + } char* p = strstr(buf, tag); if (!p) return false; x = atoi(p+strlen(tag)); @@ -46,6 +63,14 @@ bool parse_int(char* buf, char* tag, int& x) { } bool parse_double(char* buf, char* tag, double& x) { + if(buf==NULL) { + fprintf(stderr, "error: parse_double: unexpected NULL pointer buf\n"); + return false; + } + if(tag==NULL) { + fprintf(stderr, "error: parse_double: unexpected NULL pointer tag\n"); + return false; + } char* p = strstr(buf, tag); if (!p) return false; x = atof(p+strlen(tag)); @@ -53,6 +78,18 @@ bool parse_double(char* buf, char* tag, double& x) { } bool parse_str(char* buf, char* tag, char* x) { + if(buf==NULL) { + fprintf(stderr, "error: parse_str: unexpected NULL pointer buf\n"); + return false; + } + if(tag==NULL) { + fprintf(stderr, "error: parse_str: unexpected NULL pointer tag\n"); + return false; + } + if(x==NULL) { + fprintf(stderr, "error: parse_str: unexpected NULL pointer x\n"); + return false; + } char* p = strstr(buf, tag); if (!p) return false; p = strchr(p, '>'); @@ -64,7 +101,15 @@ bool parse_str(char* buf, char* tag, char* x) { void parse_attr(char* buf, char* name, char* out) { char* p, *q; - + if(buf==NULL) { + fprintf(stderr, "error: parse_attr: unexpected NULL pointer buf\n"); + } + if(name==NULL) { + fprintf(stderr, "error: parse_attr: unexpected NULL pointer name\n"); + } + if(out==NULL) { + fprintf(stderr, "error: parse_attr: unexpected NULL pointer out\n"); + } strcpy(out, ""); p = strstr(buf, name); if (!p) return; @@ -79,7 +124,12 @@ void parse_attr(char* buf, char* name, char* out) { void copy_stream(FILE* in, FILE* out) { char buf[1024]; int n, m; - + if(in==NULL) { + fprintf(stderr, "error: copy_stream: unexpected NULL pointer in\n"); + } + if(out==NULL) { + fprintf(stderr, "error: copy_stream: unexpected NULL pointer out\n"); + } while (1) { n = fread(buf, 1, 1024, in); m = fwrite(buf, 1, n, out); @@ -88,6 +138,9 @@ void copy_stream(FILE* in, FILE* out) { } void strcatdup(char*& p, char* buf) { + if(buf==NULL) { + fprintf(stderr, "error: strcatdup: unexpected NULL pointer buf\n"); + } p = (char*)realloc(p, strlen(p) + strlen(buf)+1); if (!p) { fprintf(stderr, "strcatdup: realloc failed\n"); @@ -98,7 +151,18 @@ void strcatdup(char*& p, char* buf) { int dup_element_contents(FILE* in, char* end_tag, char** pp) { char buf[256]; - + if(in==NULL) { + fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer in\n"); + return ERR_NULL; + } + if(end_tag==NULL) { + fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer end_tag\n"); + return ERR_NULL; + } + if(pp==NULL) { + fprintf(stderr, "error: dup_element_contents: unexpected NULL pointer pp\n"); + return ERR_NULL; + } char* p = strdup(""); while (fgets(buf, 256, in)) { if (strstr(buf, end_tag)) { diff --git a/lib/shmem.C b/lib/shmem.C index 8cb5077f69..ec94bcc124 100755 --- a/lib/shmem.C +++ b/lib/shmem.C @@ -1,11 +1,13 @@ #include #include #include +#include #include "shmem.h" int create_shmem(key_t key, int size, void** pp){ int id; + assert(pp!=NULL); id = shmget(key, size, IPC_CREAT|0777); if (id < 0) { perror("create_shmem: shmget"); @@ -41,7 +43,7 @@ int destroy_shmem(key_t key){ int attach_shmem(key_t key, void** pp){ void* p; int id; - + assert(pp!=NULL); id = shmget(key, 0, 0); if (id < 0) { perror("attach_shmem: shmget"); @@ -58,7 +60,7 @@ int attach_shmem(key_t key, void** pp){ int detach_shmem(void* p) { int retval; - + assert(p!=NULL); retval = shmdt((char *)p); if (retval) perror("detach_shmem: shmdt"); return retval; diff --git a/sched/Makefile.in b/sched/Makefile.in index 90619eabfc..42052c4c90 100644 --- a/sched/Makefile.in +++ b/sched/Makefile.in @@ -5,12 +5,18 @@ VPATH = @srcdir@ all: cgi +ifndef BOINC_KEY +BOINC_KEY = 0xdadacafe +endif + CFLAGS = -g -Wall @DEFS@ \ -I@top_srcdir@/db \ -I@top_srcdir@/lib \ -I@top_srcdir@/RSAEuro/source \ -I@top_srcdir@/tools \ - -I/usr/local/mysql/include + -I/usr/local/mysql/include \ + -DBOINC_KEY_DIR=\"$(BOINC_KEY_DIR)\" \ + -DBOINC_KEY=$(BOINC_KEY) CC = g++ $(CFLAGS) diff --git a/sched/feeder.C b/sched/feeder.C index f55ca6f629..829234151d 100644 --- a/sched/feeder.C +++ b/sched/feeder.C @@ -42,6 +42,7 @@ // has completed the request. #include +#include #if HAVE_UNISTD_H #include #endif @@ -56,7 +57,7 @@ int check_trigger(SCHED_SHMEM* ssp) { FILE* f; char buf[256]; - + assert(ssp!=NULL); f = fopen(TRIGGER_FILENAME, "r"); if (!f) return 0; fread(buf, 1, 256, f); @@ -97,7 +98,7 @@ void feeder_loop(SCHED_SHMEM* ssp) { RESULT result; WORKUNIT wu; bool no_wus, collision, restarted_enum; - + assert(ssp!=NULL); while (1) { nadditions = 0; ncollisions = 0; diff --git a/sched/file_upload_handler.C b/sched/file_upload_handler.C index 1ebfde35c2..ed043fb5cb 100644 --- a/sched/file_upload_handler.C +++ b/sched/file_upload_handler.C @@ -20,6 +20,7 @@ #include #include +#include #include "parse.h" #include "crypt.h" @@ -40,7 +41,7 @@ struct FILE_INFO { int FILE_INFO::parse(FILE* in) { char buf[256]; int retval; - + assert(in!=NULL); memset(this, 0, sizeof(FILE_INFO)); signed_xml = strdup(""); while (fgets(buf, 256, in)) { @@ -59,6 +60,7 @@ int FILE_INFO::parse(FILE* in) { } int print_status(int status, char* message) { + assert(message!=NULL); printf("Content-type: text/plain\n\n%d\n", status); if (message) printf("%s\n", message); #if 0 @@ -77,7 +79,10 @@ int copy_socket_to_file(FILE* in, char* path, double offset, double nbytes) { FILE* out; int retval, n, m; double bytes_left; - + assert(in!=NULL); + assert(path!=NULL); + assert(offset>=0); + assert(nbytes>=0); out = fopen(path, "wb"); if (!out) { print_status(-1, "can't open file"); @@ -119,7 +124,7 @@ int handle_request(FILE* in, R_RSA_PUBLIC_KEY& key) { FILE_INFO file_info; int retval; bool is_valid; - + assert(in!=NULL); while (fgets(buf, 256, in)) { if (match_tag(buf, "")) { retval = file_info.parse(in); diff --git a/sched/handle_request.C b/sched/handle_request.C index 49e6b46989..cfc53a6f84 100644 --- a/sched/handle_request.C +++ b/sched/handle_request.C @@ -21,6 +21,7 @@ #include #include #include +#include #include "db.h" #include "backend_lib.h" @@ -48,6 +49,7 @@ double estimate_duration(WORKUNIT& wu, HOST& host) { //inserts an xml tag in xml_doc with an estimation of how many seconds //a workunit will take to complete int insert_time_tag(WORKUNIT& wu, double seconds) { + assert(seconds>=0); char *location; location = strstr(wu.xml_doc, "
"); if ((location - wu.xml_doc) > (MAX_BLOB_SIZE - 64)) { @@ -72,7 +74,7 @@ int add_wu_to_reply( APP* app; APP_VERSION* app_version; int retval; - + assert(seconds_to_complete>=0); app = ss.lookup_app(wu.appid); if (!app) return -1; app_version = ss.lookup_app_version(app->id, platform.id, app->prod_vers); @@ -448,7 +450,8 @@ void handle_request( ) { SCHEDULER_REQUEST sreq; SCHEDULER_REPLY sreply; - + assert(fin!=NULL); + assert(fout!=NULL); memset(&sreq, 0, sizeof(sreq)); sreq.parse(fin); diff --git a/sched/main.C b/sched/main.C index f2e6f5caf0..f9efae5401 100644 --- a/sched/main.C +++ b/sched/main.C @@ -20,6 +20,7 @@ #include #include +#include #include "db.h" #include "parse.h" @@ -29,9 +30,9 @@ #define REQ_FILE_PREFIX "/tmp/boinc_req_" #define REPLY_FILE_PREFIX "/tmp/boinc_reply_" -#define BOINC_KEY_DIR "/home/david/boinc_keys" int return_error(char* p) { + assert(p!=NULL); fprintf(stderr, "BOINC server: %s\n", p); printf("%s\n", p); return 1; diff --git a/sched/sched_shmem.C b/sched/sched_shmem.C index 011cb14295..2d20ca753e 100644 --- a/sched/sched_shmem.C +++ b/sched/sched_shmem.C @@ -1,5 +1,6 @@ #include #include +#include #include "db.h" @@ -33,6 +34,7 @@ int SCHED_SHMEM::verify() { } static void overflow(char* table) { + assert(table!=NULL); fprintf(stderr, "The SCHED_SHMEM structure is too small for table %s.\n" "Increase the size and restart feeder and fcgi.\n", @@ -72,7 +74,7 @@ int SCHED_SHMEM::scan_tables() { PLATFORM* SCHED_SHMEM::lookup_platform(char* name) { int i; - + assert(name!=NULL); for (i=0; i=0); for (i=0; iappid == appid && avp->platformid == platformid && avp->version_num == version) { diff --git a/sched/sched_shmem.h b/sched/sched_shmem.h index a86093de00..3cb417bd82 100644 --- a/sched/sched_shmem.h +++ b/sched/sched_shmem.h @@ -1,6 +1,8 @@ #include "db.h" +#ifndef BOINC_KEY #define BOINC_KEY 0xdadacafe +#endif #define MAX_PLATFORMS 50 #define MAX_APPS 10 diff --git a/sched/server_types.C b/sched/server_types.C index 51099551da..54cde2cc54 100644 --- a/sched/server_types.C +++ b/sched/server_types.C @@ -18,6 +18,7 @@ // #include +#include #include "parse.h" #include "server_types.h" @@ -35,7 +36,7 @@ SCHEDULER_REQUEST::~SCHEDULER_REQUEST() { int SCHEDULER_REQUEST::parse(FILE* fin) { char buf[256]; RESULT result; - + assert(fin!=NULL); prefs_mod_time = 0; strcpy(authenticator, ""); hostid = 0; @@ -105,7 +106,7 @@ SCHEDULER_REPLY::~SCHEDULER_REPLY() { int SCHEDULER_REPLY::write(FILE* fout) { unsigned int i, j; - + assert(fout!=NULL); fprintf(fout, "\n" ); @@ -223,7 +224,7 @@ int APP_VERSION::write(FILE* fout, APP& app) { int RESULT::parse_from_client(FILE* fin) { char buf[256]; - + assert(fin!=NULL); memset(this, 0, sizeof(RESULT)); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; @@ -257,7 +258,7 @@ int RESULT::parse_from_client(FILE* fin) { int HOST::parse(FILE* fin) { char buf[256]; - + assert(fin!=NULL); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_int(buf, "", timezone)) continue; @@ -288,7 +289,7 @@ int HOST::parse(FILE* fin) { int HOST::parse_time_stats(FILE* fin) { char buf[256]; - + assert(fin!=NULL); while (fgets(buf, 256, fin)) { if (match_tag(buf, "")) return 0; else if (parse_double(buf, "", on_frac)) continue; @@ -334,7 +335,7 @@ int DB_CACHE::read_db() { PLATFORM* DB_CACHE::lookup_platform(char* name) { unsigned int i; - + assert(name!=NULL); for (i=0; i=0); for (i=0; iappid == appid && avp->platformid == platformid && avp->version_num == version) { diff --git a/test/master.html b/test/master.html index 60044e2e7a..fab13166f2 100644 --- a/test/master.html +++ b/test/master.html @@ -1,3 +1 @@ -

Test BOINC Project

- -http://localhost/boinc-cgi/cgi +http://maggie.ssl.berkeley.edu/cgi-bin/boinc-cgi/mgary/fcgi diff --git a/test/max_water_prefs.xml b/test/max_water_prefs.xml deleted file mode 100644 index 24bb1f1de8..0000000000 --- a/test/max_water_prefs.xml +++ /dev/null @@ -1,2 +0,0 @@ -2592000 -1 diff --git a/test/min_water_prefs.xml b/test/min_water_prefs.xml deleted file mode 100644 index d205a8787c..0000000000 --- a/test/min_water_prefs.xml +++ /dev/null @@ -1,2 +0,0 @@ -172800 -300 diff --git a/test/normal_water_prefs.xml b/test/normal_water_prefs.xml deleted file mode 100644 index d205a8787c..0000000000 --- a/test/normal_water_prefs.xml +++ /dev/null @@ -1,2 +0,0 @@ -172800 -300 diff --git a/test/prefs1.xml b/test/prefs1.xml index 7cad08a019..514bcf4dd5 100644 --- a/test/prefs1.xml +++ b/test/prefs1.xml @@ -4,7 +4,7 @@ 1 1 - http://localhost/index.html + http://maggie.ssl.berkeley.edu/mgary_fcgi.html 3f7b90793a0175ad0bda68684e8bd136 diff --git a/test/test_max_water_prefs.php b/test/test_max_water_prefs.php deleted file mode 100755 index 0684523398..0000000000 --- a/test/test_max_water_prefs.php +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/local/bin/php - diff --git a/test/test_min_water_prefs.php b/test/test_min_water_prefs.php deleted file mode 100755 index 23f3245e28..0000000000 --- a/test/test_min_water_prefs.php +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/local/bin/php - diff --git a/test/test_normal_water_prefs.php b/test/test_normal_water_prefs.php deleted file mode 100755 index 37f2dbc30b..0000000000 --- a/test/test_normal_water_prefs.php +++ /dev/null @@ -1,31 +0,0 @@ -#! /usr/local/bin/php - diff --git a/tools/add.C b/tools/add.C index 74a4521e10..b19d6db465 100644 --- a/tools/add.C +++ b/tools/add.C @@ -40,6 +40,7 @@ #include "db.h" #include "backend_lib.h" #include "md5_file.h" +#include "crypt.h" APP app; PLATFORM platform; diff --git a/tools/backend_lib.C b/tools/backend_lib.C index 514c665f87..b2a4b6da79 100644 --- a/tools/backend_lib.C +++ b/tools/backend_lib.C @@ -20,6 +20,7 @@ #include #include #include +#include #include "db.h" #include "crypt.h" @@ -38,6 +39,8 @@ #define DOWNLOAD_URL "http://localhost/download/" int read_file(FILE* f, char* buf) { + assert(f!=NULL); + assert(buf!=NULL); int n = fread(buf, 1, MAX_BLOB_SIZE, f); buf[n] = 0; return 0; @@ -45,7 +48,8 @@ int read_file(FILE* f, char* buf) { int read_filename(char* path, char* buf) { int retval; - + assert(path!=NULL); + assert(buf!=NULL); FILE* f = fopen(path, "r"); if (!f) return -1; retval = read_file(f, buf); @@ -66,7 +70,12 @@ static int process_wu_template( bool found; int i; double nbytes; - + assert(wu_name!=NULL); + assert(tmplate!=NULL); + assert(out!=NULL); + assert(dirpath!=NULL); + assert(infiles!=NULL); + assert(n>=0); strcpy(out, tmplate); while (1) { found = false; @@ -129,7 +138,7 @@ int create_result( char base_outfile_name[256]; int retval; FILE* result_template_file, *tempfile; - + assert(result_template_filename!=NULL); memset(&r, 0, sizeof(r)); r.create_time = time(0); r.workunitid = wu.id; @@ -167,7 +176,12 @@ int create_work( R_RSA_PRIVATE_KEY& key ) { int i, retval; - + assert(wu_template!=NULL); + assert(result_template_file!=NULL); + assert(nresults>=0); + assert(infile_dir!=NULL); + assert(infiles!=NULL); + assert(ninfiles>=0); wu.create_time = time(0); retval = process_wu_template( wu.name, wu_template, wu.xml_doc, infile_dir, infiles, ninfiles diff --git a/tools/process_result_template.C b/tools/process_result_template.C index df09e13aed..6079159d76 100644 --- a/tools/process_result_template.C +++ b/tools/process_result_template.C @@ -26,6 +26,7 @@ #include #include +#include #include "db.h" #include "parse.h" @@ -52,7 +53,11 @@ int process_result_template( int i; bool found; - + assert(in!=NULL); + assert(out!=NULL); + assert(base_filename!=NULL); + assert(wu_name!=NULL); + assert(result_name!=NULL); while (fgets(buf, 256, in)) { // when we reach the end of a element,