From 57fc665a9121b8eff8ca5cdedcd1a4a4ead04a73 Mon Sep 17 00:00:00 2001 From: Karl Chen Date: Tue, 25 Nov 2003 07:40:45 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=2680 --- checkin_notes | 9 ++++++++- db/boinc_db.C | 24 ++++++++++++++++++------ test/cgiserver.py | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/checkin_notes b/checkin_notes index bb796ba487..214507e8fe 100755 --- a/checkin_notes +++ b/checkin_notes @@ -7776,7 +7776,14 @@ Karl 2003-11-22 client_types.C Karl 2003-11-24 - - testbase fixes + - fixed bug in boinc_db.C which causes SQL lookups to seg fault if any of + the 'seti_*' grandfather fields are NULL (how does the current beta test + run at all?!) + + db/ + boinc_db.C + + - testbase tweaks test/ testbase.py diff --git a/db/boinc_db.C b/db/boinc_db.C index 51e70356e9..90cd3e6eee 100644 --- a/db/boinc_db.C +++ b/db/boinc_db.C @@ -32,6 +32,18 @@ static struct random_init { } } random_init; +// if SQL columns are not 'not null', you must use these safe_atoi, safe_atof +// instead of atoi, atof, since the strings returned by MySQL may be NULL. +inline int safe_atoi(const char* s) +{ + return s && atoi(s); +} + +inline float safe_atof(const char* s) +{ + return s && atof(s); +} + void PROJECT::clear() {memset(this, 0, sizeof(*this));} void PLATFORM::clear() {memset(this, 0, sizeof(*this));} void CORE_VERSION::clear() {memset(this, 0, sizeof(*this));} @@ -236,11 +248,11 @@ void DB_USER::db_parse(MYSQL_ROW &r) { strcpy2(url, r[i++]); send_email = atoi(r[i++]); show_hosts = atoi(r[i++]); - posts = atoi(r[i++]); - seti_id = atoi(r[i++]); - seti_nresults = atoi(r[i++]); - seti_last_result_time = atoi(r[i++]); - seti_total_cpu = atof(r[i++]); + posts = safe_atoi(r[i++]); + seti_id = safe_atoi(r[i++]); + seti_nresults = safe_atoi(r[i++]); + seti_last_result_time = safe_atoi(r[i++]); + seti_total_cpu = safe_atof(r[i++]); } void DB_TEAM::db_print(char* buf){ @@ -293,7 +305,7 @@ void DB_TEAM::db_parse(MYSQL_ROW &r) { strcpy2(country, r[i++]); total_credit = atof(r[i++]); expavg_credit = atof(r[i++]); - seti_id = atoi(r[i++]); + seti_id = safe_atoi(r[i++]); } void DB_HOST::db_print(char* buf){ diff --git a/test/cgiserver.py b/test/cgiserver.py index e0d491c3cf..cbe07665b0 100755 --- a/test/cgiserver.py +++ b/test/cgiserver.py @@ -5,6 +5,7 @@ import BaseHTTPServer, CGIHTTPServer import sys, os, urllib, select +import random, time # XXX php_path = None possible_php_paths = [ '/usr/lib/cgi-bin/php4', @@ -159,6 +160,23 @@ class PHPHTTPRequestHandler(CGIHTTPServer.CGIHTTPRequestHandler): return # Child try: + if 0: + time.sleep(.1) + fn = '/tmp/a%d'%random.randint(1000,10000) + f = open(fn, 'w') + s = '' + while select.select([self.rfile], [], [], 0)[0]: + try: + c = self.rfile.read(1) + if not c: + break + s += c + except: + break + print '### input:', repr(s) + print >>f, s + f.close() + self.rfile = open(fn, 'r') os.dup2(self.rfile.fileno(), 0) os.dup2(self.wfile.fileno(), 1) os.chdir(self.translate_path(dir)) # KC