From 51ca17796b4cccf886030f15e68e7659ed356f86 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 10 Jul 2009 22:59:45 +0000 Subject: [PATCH] - 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 --- checkin_notes | 10 ++++++++++ lib/mfile.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/checkin_notes b/checkin_notes index 6f18989e51..93bae77909 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 diff --git a/lib/mfile.cpp b/lib/mfile.cpp index 41439c7775..0ea0bca17c 100644 --- a/lib/mfile.cpp +++ b/lib/mfile.cpp @@ -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;