*** empty log message ***

svn path=/trunk/boinc/; revision=10976
This commit is contained in:
David Anderson 2006-08-23 03:34:30 +00:00
parent 1893f71f7c
commit 5fea7f0226
7 changed files with 128 additions and 100 deletions

View File

@ -9182,3 +9182,18 @@ Rom 22 Aug 2006
Rom 22 Aug 2006
- Tag for 5.5.15 release, all platforms
boinc_core_release_5_5_15
David 22 Aug 2006
- Change new XML parser to prevent buffer overrun on string parsing
- User web: fix bug in moving post from one thread to another
(from David Kim)
client/
log_flags.C
html/inc/
forum_post.inc
lib/
parse.C,h
prefs.C
sched/
sched_config.C

View File

@ -57,7 +57,7 @@ int LOG_FLAGS::parse(XML_PARSER& xp) {
char tag[1024];
bool is_tag;
while (!xp.get(tag, is_tag)) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
msg_printf(NULL, MSG_ERROR,
"Unexpected text %s in %s", tag, CONFIG_FILE
@ -108,7 +108,7 @@ int CONFIG::parse_options(XML_PARSER& xp) {
char tag[1024];
bool is_tag;
while (!xp.get(tag, is_tag)) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
msg_printf(NULL, MSG_ERROR,
"Unexpected text %s in %s", tag, CONFIG_FILE
@ -138,7 +138,7 @@ int CONFIG::parse(FILE* f) {
mf.init_file(f);
if (!xp.parse_start("cc_config")) return ERR_XML_PARSE;
while (!xp.get(tag, is_tag)) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
msg_printf(NULL, MSG_ERROR,
"Unexpected text %s in %s", tag, CONFIG_FILE

View File

@ -163,11 +163,11 @@ class Post {
* - Moving the post
* - incrementing the destination thread postcount by 1
*/
function move($thread){
function move($destthread){
$thread = $this->getThread();
return ($thread->decPostCount() &&
$this->dbhandler->updatePost($this, "thread", $thread->getID()) &&
$thread->incPostCount());
return ($thread->decPostCount()
&& $this->dbhandler->updatePost($this, "thread", $destthread->getID())
&& $destthread->incPostCount());
}
/**
@ -184,4 +184,4 @@ class Post {
}
?>
?>

View File

@ -110,8 +110,8 @@ bool parse_str(const char* buf, const char* tag, string& dest) {
return true;
}
// parse a string of the form name="string";
// returns string in dest
// parse a string of the form 'xxx name="value" xxx';
// returns value in dest
//
void parse_attr(const char* buf, const char* name, char* dest, int len) {
const char* p;
@ -430,7 +430,7 @@ bool XML_PARSER::scan_nonws(int& first_char) {
// and copy intervening text to buf.
// Return true iff reached EOF
//
bool XML_PARSER::scan_tag(char* buf) {
bool XML_PARSER::scan_tag(char* buf, int len) {
int c;
while (1) {
c = f->getc();
@ -439,7 +439,9 @@ bool XML_PARSER::scan_tag(char* buf) {
*buf = 0;
return false;
}
*buf++ = c;
if (--len > 0) {
*buf++ = c;
}
}
}
@ -447,7 +449,7 @@ bool XML_PARSER::scan_tag(char* buf) {
// ungetc() that so we read it again
// Return true iff reached EOF
//
bool XML_PARSER::copy_until_tag(char* buf) {
bool XML_PARSER::copy_until_tag(char* buf, int len) {
int c;
while (1) {
c = f->getc();
@ -457,7 +459,9 @@ bool XML_PARSER::copy_until_tag(char* buf) {
*buf = 0;
return false;
}
*buf++ = c;
if (--len > 0) {
*buf++ = c;
}
}
}
@ -465,19 +469,19 @@ bool XML_PARSER::copy_until_tag(char* buf) {
// Strip whitespace at start and end.
// Return true iff reached EOF
//
bool XML_PARSER::get(char* buf, bool& is_tag) {
bool XML_PARSER::get(char* buf, int len, bool& is_tag) {
bool eof;
int c;
eof = scan_nonws(c);
if (eof) return true;
if (c == '<') {
eof = scan_tag(buf);
eof = scan_tag(buf, len);
if (eof) return true;
is_tag = true;
} else {
buf[0] = c;
eof = copy_until_tag(buf+1);
eof = copy_until_tag(buf+1, len-1);
if (eof) return true;
is_tag = false;
}
@ -490,7 +494,9 @@ bool XML_PARSER::get(char* buf, bool& is_tag) {
// and by the matching close tag, return the string in "buf",
// and return true.
//
bool XML_PARSER::parse_str(char* parsed_tag, char* start_tag, char* buf) {
bool XML_PARSER::parse_str(
char* parsed_tag, char* start_tag, char* buf, int len
) {
bool is_tag, eof;
char end_tag[256], tag[256];
@ -504,13 +510,13 @@ bool XML_PARSER::parse_str(char* parsed_tag, char* start_tag, char* buf) {
}
if (strcmp(parsed_tag, start_tag)) return false;
eof = get(buf, is_tag);
eof = get(buf, len, is_tag);
if (eof) return false;
if (is_tag) return false;
end_tag[0] = '/';
strcpy(end_tag+1, start_tag);
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof) return false;
if (!is_tag) return false;
if (strcmp(tag, end_tag)) return false;
@ -526,7 +532,7 @@ bool XML_PARSER::parse_int(char* parsed_tag, char* start_tag, int& i) {
if (strcmp(parsed_tag, start_tag)) return false;
eof = get(buf, is_tag);
eof = get(buf, sizeof(buf), is_tag);
if (eof) return false;
if (is_tag) return false;
i = strtol(buf, &end, 0);
@ -534,7 +540,7 @@ bool XML_PARSER::parse_int(char* parsed_tag, char* start_tag, int& i) {
end_tag[0] = '/';
strcpy(end_tag+1, start_tag);
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof) return false;
if (!is_tag) return false;
if (strcmp(tag, end_tag)) return false;
@ -550,7 +556,7 @@ bool XML_PARSER::parse_double(char* parsed_tag, char* start_tag, double& x) {
if (strcmp(parsed_tag, start_tag)) return false;
eof = get(buf, is_tag);
eof = get(buf, sizeof(buf), is_tag);
if (eof) return false;
if (is_tag) return false;
x = strtod(buf, &end);
@ -558,7 +564,7 @@ bool XML_PARSER::parse_double(char* parsed_tag, char* start_tag, double& x) {
end_tag[0] = '/';
strcpy(end_tag+1, start_tag);
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof) return false;
if (!is_tag) return false;
if (strcmp(tag, end_tag)) return false;
@ -585,7 +591,7 @@ bool XML_PARSER::parse_bool(char* parsed_tag, char* start_tag, bool& b) {
//
if (strcmp(parsed_tag, start_tag)) return false;
eof = get(buf, is_tag);
eof = get(buf, sizeof(buf), is_tag);
if (eof) return false;
if (is_tag) return false;
b = (bool)strtol(buf, &end, 0);
@ -593,7 +599,7 @@ bool XML_PARSER::parse_bool(char* parsed_tag, char* start_tag, bool& b) {
end_tag[0] = '/';
strcpy(end_tag+1, start_tag);
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof) return false;
if (!is_tag) return false;
if (strcmp(tag, end_tag)) return false;
@ -604,12 +610,12 @@ bool XML_PARSER::parse_start(char* start_tag) {
char tag[256];
bool eof, is_tag;
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof || !is_tag ) {
return false;
}
if (strstr(tag, "?xml")) {
eof = get(tag, is_tag);
eof = get(tag, sizeof(tag), is_tag);
if (eof || !is_tag ) {
return false;
}
@ -626,16 +632,18 @@ bool XML_PARSER::parse_start(char* start_tag) {
void parse(FILE* f) {
char tag[256];
bool is_tag, flag;
MIOFILE mf;
XML_PARSER xp(f);
char name[256];
int val;
double x;
mf.init_file(f);
if (!xp.parse_start("blah")) {
printf("missing start tag\n");
return;
}
while (!xp.get(tag, is_tag)) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
printf("unexpected text: %s\n", tag);
continue;
@ -643,7 +651,7 @@ void parse(FILE* f) {
if (!strcmp(tag, "/blah")) {
printf("success\n");
return;
} else if (xp.parse_str(tag, "str", name)) {
} else if (xp.parse_str(tag, "str", name, sizeof(name))) {
printf("got str: %s\n", name);
} else if (xp.parse_int(tag, "int", val)) {
printf("got int: %d\n", val);

View File

@ -38,13 +38,13 @@
class XML_PARSER {
MIOFILE* f;
bool scan_nonws(int&);
bool scan_tag(char*);
bool copy_until_tag(char*);
bool scan_tag(char*, int);
bool copy_until_tag(char*, int);
public:
XML_PARSER(MIOFILE*);
bool get(char*, bool&);
bool get(char*, int, bool&);
bool parse_start(char*);
bool parse_str(char*, char*, char*);
bool parse_str(char*, char*, char*, int);
bool parse_int(char*, char*, int&);
bool parse_double(char*, char*, double&);
bool parse_bool(char*, char*, bool&);

View File

@ -112,16 +112,24 @@ int GLOBAL_PREFS::parse(
int GLOBAL_PREFS::parse_override(
MIOFILE& in, const char* host_venue, bool& found_venue
) {
char buf[256], buf2[256];
bool in_venue = false, in_correct_venue=false;
char tag[256], buf2[256];
bool in_venue = false, in_correct_venue=false, is_tag;
double dtemp;
XML_PARSER xp(&in);
found_venue = false;
while (in.fgets(buf, 256)) {
if (!xp.parse_start("global_preferences")) {
return ERR_XML_PARSE;
}
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
printf("unexpected text: %s\n", tag);
continue;
}
if (in_venue) {
if (match_tag(buf, "</venue>")) {
if (!strcmp(tag, "/venue")) {
if (in_correct_venue) {
break;
return 0;
} else {
in_venue = false;
continue;
@ -130,9 +138,9 @@ int GLOBAL_PREFS::parse_override(
if (!in_correct_venue) continue;
}
} else {
if (match_tag(buf, "<venue")) {
if (strstr(tag, "venue")) {
in_venue = true;
parse_attr(buf, "name", buf2, sizeof(buf2));
parse_attr(tag, "name", buf2, sizeof(buf2));
if (!strcmp(buf2, host_venue)) {
defaults();
clear_bools();
@ -144,81 +152,79 @@ int GLOBAL_PREFS::parse_override(
continue;
}
}
if (match_tag(buf, "<global_preferences>")) {
if (xp.parse_str(tag, "source_project", source_project, sizeof(source_project))) {
continue;
} else if (parse_str(buf, "<source_project>", source_project, sizeof(source_project))) {
} else if (xp.parse_str(tag, "source_scheduler", source_scheduler, sizeof(source_scheduler))) {
continue;
} else if (parse_str(buf, "<source_scheduler>", source_scheduler, sizeof(source_scheduler))) {
} else if (xp.parse_int(tag, "mod_time", mod_time)) {
continue;
} else if (parse_int(buf, "<mod_time>", mod_time)) {
} else if (!strcmp(tag, "/global_preferences")) {
return 0;
} else if (xp.parse_bool(tag, "run_on_batteries", run_on_batteries)) {
continue;
} else if (match_tag(buf, "</global_preferences>")) {
break;
} else if (parse_bool(buf, "run_on_batteries", run_on_batteries)) {
} else if (xp.parse_bool(tag, "run_if_user_active", run_if_user_active)) {
continue;
} else if (parse_bool(buf, "run_if_user_active", run_if_user_active)) {
} else if (xp.parse_int(tag, "start_hour", start_hour)) {
continue;
} else if (parse_int(buf, "<start_hour>", start_hour)) {
} else if (xp.parse_int(tag, "end_hour", end_hour)) {
continue;
} else if (parse_int(buf, "<end_hour>", end_hour)) {
} else if (xp.parse_int(tag, "net_start_hour", net_start_hour)) {
continue;
} else if (parse_int(buf, "<net_start_hour>", net_start_hour)) {
} else if (xp.parse_int(tag, "net_end_hour", net_end_hour)) {
continue;
} else if (parse_int(buf, "<net_end_hour>", net_end_hour)) {
} else if (xp.parse_bool(tag, "leave_apps_in_memory", leave_apps_in_memory)) {
continue;
} else if (parse_bool(buf, "leave_apps_in_memory", leave_apps_in_memory)) {
} else if (xp.parse_bool(tag, "confirm_before_connecting", confirm_before_connecting)) {
continue;
} else if (parse_bool(buf, "confirm_before_connecting", confirm_before_connecting)) {
} else if (xp.parse_bool(tag, "hangup_if_dialed", hangup_if_dialed)) {
continue;
} else if (parse_bool(buf, "hangup_if_dialed", hangup_if_dialed)) {
} else if (xp.parse_bool(tag, "run_minimized", run_minimized)) {
continue;
} else if (parse_bool(buf, "run_minimized", run_minimized)) {
} else if (xp.parse_bool(tag, "run_on_startup", run_on_startup)) {
continue;
} else if (parse_bool(buf, "run_on_startup", run_on_startup)) {
} else if (xp.parse_bool(tag, "dont_verify_images", dont_verify_images)) {
continue;
} else if (parse_bool(buf, "dont_verify_images", dont_verify_images)) {
} else if (xp.parse_double(tag, "work_buf_min_days", work_buf_min_days)) {
continue;
} else if (parse_double(buf, "<work_buf_min_days>", work_buf_min_days)) {
continue;
} else if (parse_int(buf, "<max_cpus>", max_cpus)) {
} else if (xp.parse_int(tag, "max_cpus", max_cpus)) {
if (max_cpus < 1) max_cpus = 1;
continue;
} else if (parse_double(buf, "<disk_interval>", disk_interval)) {
} else if (xp.parse_double(tag, "disk_interval", disk_interval)) {
if (disk_interval<0) disk_interval = 0;
continue;
} else if (parse_double(buf, "<cpu_scheduling_period_minutes>", cpu_scheduling_period_minutes)) {
} else if (xp.parse_double(tag, "cpu_scheduling_period_minutes", cpu_scheduling_period_minutes)) {
if (cpu_scheduling_period_minutes < 0.0001) cpu_scheduling_period_minutes = 60;
continue;
} else if (parse_double(buf, "<disk_max_used_gb>", disk_max_used_gb)) {
} else if (xp.parse_double(tag, "disk_max_used_gb", disk_max_used_gb)) {
continue;
} else if (parse_double(buf, "<disk_max_used_pct>", disk_max_used_pct)) {
} else if (xp.parse_double(tag, "disk_max_used_pct", disk_max_used_pct)) {
continue;
} else if (parse_double(buf, "<disk_min_free_gb>", disk_min_free_gb)) {
} else if (xp.parse_double(tag, "disk_min_free_gb", disk_min_free_gb)) {
continue;
} else if (parse_double(buf, "<vm_max_used_pct>", vm_max_used_pct)) {
} else if (xp.parse_double(tag, "vm_max_used_pct", vm_max_used_pct)) {
continue;
} else if (parse_double(buf, "<idle_time_to_run>", idle_time_to_run)) {
} else if (xp.parse_double(tag, "idle_time_to_run", idle_time_to_run)) {
continue;
} else if (parse_double(buf, "<max_bytes_sec_up>", max_bytes_sec_up)) {
} else if (xp.parse_double(tag, "max_bytes_sec_up", max_bytes_sec_up)) {
if (max_bytes_sec_up <= 0) max_bytes_sec_up = 1e12;
continue;
} else if (parse_double(buf, "<max_bytes_sec_down>", max_bytes_sec_down)) {
} else if (xp.parse_double(tag, "max_bytes_sec_down", max_bytes_sec_down)) {
if (max_bytes_sec_down <= 0) max_bytes_sec_down = 1e12;
continue;
#if 0
} else if (parse_int(buf, "<max_memory_mbytes>", max_memory_mbytes)) {
} else if (xp.parse_int(tag, "max_memory_mbytes", max_memory_mbytes)) {
continue;
#endif
} else if (parse_int(buf, "<cpu_affinity>", cpu_affinity)) {
} else if (xp.parse_int(tag, "cpu_affinity", cpu_affinity)) {
continue;
} else if (parse_double(buf, "<cpu_usage_limit>", dtemp)) {
} else if (xp.parse_double(tag, "cpu_usage_limit", dtemp)) {
if (dtemp > 0 && dtemp <= 100) {
cpu_usage_limit = dtemp;
}
continue;
}
}
return 0;
return ERR_XML_PARSE;
}
// Parse global prefs file
@ -290,5 +296,4 @@ int GLOBAL_PREFS::write(MIOFILE& f) {
return 0;
}
const char *BOINC_RCSID_3fb442bb02 = "$Id$";

View File

@ -53,7 +53,7 @@ int SCHED_CONFIG::parse(FILE* f) {
if (!xp.parse_start("boinc")) return ERR_XML_PARSE;
if (!xp.parse_start("config")) return ERR_XML_PARSE;
while (!xp.get(tag, is_tag)) {
while (!xp.get(tag, sizeof(tag), is_tag)) {
if (!is_tag) {
fprintf(stderr, "SCHED_CONFIG::parse(): unexpected text %s\n", tag);
continue;
@ -64,20 +64,20 @@ int SCHED_CONFIG::parse(FILE* f) {
if (!strcmp(hostname, db_host)) strcpy(db_host, "localhost");
return 0;
}
else if (xp.parse_str(tag, "master_url", master_url)) continue;
else if (xp.parse_str(tag, "long_name", long_name)) continue;
else if (xp.parse_str(tag, "db_name", db_name)) continue;
else if (xp.parse_str(tag, "db_user", db_user)) continue;
else if (xp.parse_str(tag, "db_passwd", db_passwd)) continue;
else if (xp.parse_str(tag, "db_host", db_host)) continue;
else if (xp.parse_str(tag, "master_url", master_url, sizeof(master_url))) continue;
else if (xp.parse_str(tag, "long_name", long_name, sizeof(long_name))) continue;
else if (xp.parse_str(tag, "db_name", db_name, sizeof(db_name))) continue;
else if (xp.parse_str(tag, "db_user", db_user, sizeof(db_user))) continue;
else if (xp.parse_str(tag, "db_passwd", db_passwd, sizeof(db_passwd))) continue;
else if (xp.parse_str(tag, "db_host", db_host, sizeof(db_host))) continue;
else if (xp.parse_int(tag, "shmem_key", shmem_key)) continue;
else if (xp.parse_str(tag, "key_dir", key_dir)) continue;
else if (xp.parse_str(tag, "download_url", download_url)) continue;
else if (xp.parse_str(tag, "download_dir", download_dir)) continue;
else if (xp.parse_str(tag, "download_dir_alt", download_dir_alt)) continue;
else if (xp.parse_str(tag, "upload_url", upload_url)) continue;
else if (xp.parse_str(tag, "upload_dir", upload_dir)) continue;
else if (xp.parse_str(tag, "sched_lockfile_dir", sched_lockfile_dir)) continue;
else if (xp.parse_str(tag, "key_dir", key_dir, sizeof(key_dir))) continue;
else if (xp.parse_str(tag, "download_url", download_url, sizeof(download_url))) continue;
else if (xp.parse_str(tag, "download_dir", download_dir, sizeof(download_dir))) continue;
else if (xp.parse_str(tag, "download_dir_alt", download_dir_alt, sizeof(download_dir_alt))) continue;
else if (xp.parse_str(tag, "upload_url", upload_url, sizeof(upload_url))) continue;
else if (xp.parse_str(tag, "upload_dir", upload_dir, sizeof(upload_dir))) continue;
else if (xp.parse_str(tag, "sched_lockfile_dir", sched_lockfile_dir, sizeof(sched_lockfile_dir))) continue;
else if (xp.parse_bool(tag, "one_result_per_user_per_wu", one_result_per_user_per_wu)) continue;
else if (xp.parse_bool(tag, "non_cpu_intensive", non_cpu_intensive)) continue;
else if (xp.parse_bool(tag, "verify_files_on_app_start", verify_files_on_app_start)) continue;
@ -115,7 +115,7 @@ int SCHED_CONFIG::parse(FILE* f) {
else if (xp.parse_double(tag, "default_disk_max_used_gb", default_disk_max_used_gb)) continue;
else if (xp.parse_double(tag, "default_disk_max_used_pct", default_disk_max_used_pct)) continue;
else if (xp.parse_double(tag, "default_disk_min_free_gb", default_disk_min_free_gb)) continue;
else if (xp.parse_str(tag, "symstore", symstore)) continue;
else if (xp.parse_str(tag, "symstore", symstore, sizeof(symstore))) continue;
else if (xp.parse_double(tag, "next_rpc_delay", next_rpc_delay)) continue;
else if (xp.parse_bool(tag, "dont_delete_batches", dont_delete_batches)) continue;
else if (xp.parse_int(tag, "sched_debug_level", sched_debug_level)) continue;
@ -123,15 +123,15 @@ int SCHED_CONFIG::parse(FILE* f) {
// tags the scheduler doesn't care about
//
else if (xp.parse_str(tag, "cgi_url", temp)) continue;
else if (xp.parse_str(tag, "log_dir", temp)) continue;
else if (xp.parse_str(tag, "app_dir", temp)) continue;
else if (xp.parse_str(tag, "show_results", temp)) continue;
else if (xp.parse_str(tag, "host", temp)) continue;
else if (xp.parse_str(tag, "output_level", temp)) continue;
else if (xp.parse_str(tag, "profile_screening", temp)) continue;
else if (xp.parse_str(tag, "min_passwd_length", temp)) continue;
else if (xp.parse_str(tag, "disable_account_creation", temp)) continue;
else if (xp.parse_str(tag, "cgi_url", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "log_dir", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "app_dir", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "show_results", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "host", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "output_level", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "profile_screening", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "min_passwd_length", temp, sizeof(temp))) continue;
else if (xp.parse_str(tag, "disable_account_creation", temp, sizeof(temp))) continue;
else fprintf(stderr, "unknown tag: %s\n", tag);
}
return ERR_XML_PARSE;