- client: if malloc fails in MFILE writes, exit.

We don't check the return values of printf() anywhere,
    and it's dangerous for the client to continue if it
    thinks something got written that didn't.
    Fixes #281

svn path=/trunk/boinc/; revision=18594
This commit is contained in:
David Anderson 2009-07-10 22:59:45 +00:00
parent 6a13bd12b8
commit 51ca17796b
2 changed files with 18 additions and 8 deletions

View File

@ -6245,3 +6245,13 @@ David 10 July 2009
client/
client_types.cpp,h
pers_file_xfer.cpp
David 10 July 2009
- client: if malloc fails in MFILE writes, exit.
We don't check the return values of printf() anywhere,
and it's dangerous for the client to continue if it
thinks something got written that didn't.
Fixes #281
lib/
mfile.cpp

View File

@ -70,8 +70,8 @@ int MFILE::vprintf(const char* format, va_list ap) {
n = (int)strlen(buf2);
buf = (char*)realloc(buf, len+n+1);
if (!buf) {
errno = ERR_MALLOC;
return ERR_MALLOC;
fprintf(stderr, "ERROR: realloc() failed in MFILE::vprintf()\n");
exit(1);
}
strncpy(buf+len, buf2, n);
len += n;
@ -92,8 +92,8 @@ int MFILE::printf(const char* format, ...) {
size_t MFILE::write(const void *ptr, size_t size, size_t nitems) {
buf = (char *)realloc( buf, len+(size*nitems)+1 );
if (!buf) {
errno = ERR_MALLOC;
return 0;
fprintf(stderr, "ERROR: realloc() failed in MFILE::write()\n");
exit(1);
}
memcpy( buf+len, ptr, size*nitems );
len += (int)size*(int)nitems;
@ -104,8 +104,8 @@ size_t MFILE::write(const void *ptr, size_t size, size_t nitems) {
int MFILE::_putchar(char c) {
buf = (char*)realloc(buf, len+1+1);
if (!buf) {
errno = ERR_MALLOC;
return EOF;
fprintf(stderr, "ERROR: realloc() failed in MFILE::_putchar()\n");
exit(1);
}
buf[len] = c;
len++;
@ -117,8 +117,8 @@ int MFILE::puts(const char* p) {
int n = (int)strlen(p);
buf = (char*)realloc(buf, len+n+1);
if (!buf) {
errno = ERR_MALLOC;
return EOF;
fprintf(stderr, "ERROR: realloc() failed in MFILE::puts()\n");
exit(1);
}
strncpy(buf+len, p, n);
len += n;