diff options
author | Stef Walter <stef@memberwebs.com> | 2004-08-17 22:54:16 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-08-17 22:54:16 +0000 |
commit | 4faa3b65abad58a20c5e7e401361d30188460a83 (patch) | |
tree | 5c6bd3f1f2c9cc65ec9fc8d6a22824cde8fc40a1 | |
parent | 2888f640a34e34d5a85841976fb8937c4a7774a0 (diff) |
Better message handling when buffer runs out of memory.
-rw-r--r-- | common/buffer.c | 7 | ||||
-rw-r--r-- | daemon/basic.c | 2 | ||||
-rw-r--r-- | daemon/bd.c | 2 | ||||
-rw-r--r-- | daemon/digest.c | 4 | ||||
-rw-r--r-- | daemon/httpauthd.c | 6 | ||||
-rw-r--r-- | daemon/httpauthd.h | 1 | ||||
-rw-r--r-- | daemon/ldap.c | 2 | ||||
-rw-r--r-- | daemon/misc.c | 5 | ||||
-rw-r--r-- | daemon/mysql.c | 2 | ||||
-rw-r--r-- | daemon/ntlm.c | 8 | ||||
-rw-r--r-- | daemon/pgsql.c | 2 | ||||
-rw-r--r-- | daemon/simple.c | 8 | ||||
-rw-r--r-- | daemon/usuals.h | 10 |
13 files changed, 37 insertions, 22 deletions
diff --git a/common/buffer.c b/common/buffer.c index 6064cbe..cc5480f 100644 --- a/common/buffer.c +++ b/common/buffer.c @@ -71,7 +71,6 @@ void buffer_bump(ha_buffer_t* buf, int count) intl = (internal_t*)malloc(allocated); if(!intl) { - ha_messagex(NULL, LOG_CRIT, "out of memory"); buf->_dt = NULL; buf->_pp = buf->_rp = NULL; return; @@ -221,10 +220,10 @@ int ha_bufreadline(int fd, ha_buffer_t* buf) /* Fatal errors */ else if(l == -1) { - if(errno != EINTR) - ha_message(NULL, LOG_ERR, "couldn't read data"); + if(errno == EINTR) + return 0; - return 0; + return -1; } } diff --git a/daemon/basic.c b/daemon/basic.c index 6b41a36..99c2007 100644 --- a/daemon/basic.c +++ b/daemon/basic.c @@ -21,7 +21,7 @@ int basic_parse(const char* header, ha_buffer_t* buf, basic_header_t* rec) header = (const char*)ha_bufdec64(buf, header, NULL); if(!header) - return ha_buferr(buf) ? HA_CRITERROR : HA_FALSE; + return CHECK_BUF(buf) ? HA_CRITERROR : HA_FALSE; /* We have a cache key at this point so hash it */ diff --git a/daemon/bd.c b/daemon/bd.c index 9c3b429..a20b90b 100644 --- a/daemon/bd.c +++ b/daemon/bd.c @@ -624,7 +624,7 @@ int bd_process(ha_request_t* rq) { ha_bufmcat(rq->buf, "BASIC realm=\"", rq->context->realm , "\"", NULL); - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) return HA_CRITERROR; ha_addheader(rq, "WWW-Authenticate", ha_bufdata(rq->buf)); diff --git a/daemon/digest.c b/daemon/digest.c index 968399a..5d91995 100644 --- a/daemon/digest.c +++ b/daemon/digest.c @@ -338,7 +338,7 @@ int digest_pre_check(digest_context_t* dg, const ha_context_t* opts, ha_buffer_t if(ha_uriparse(buf, dg->client.uri, &d_uri) < 0) { - if(ha_buferr(buf)) + if(CHECK_BUF(buf)) return HA_CRITERROR; ha_messagex(NULL, LOG_WARNING, "digest response constains invalid uri: %s", dg->client.uri); @@ -349,7 +349,7 @@ int digest_pre_check(digest_context_t* dg, const ha_context_t* opts, ha_buffer_t if(ha_uriparse(buf, dg->server_uri, &s_uri) < 0) { - if(ha_buferr(buf)) + if(CHECK_BUF(buf)) return HA_CRITERROR; ha_messagex(NULL, LOG_ERR, "server sent us an invalid uri: %s", dg->server_uri); diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c index 4450b7a..8b8617e 100644 --- a/daemon/httpauthd.c +++ b/daemon/httpauthd.c @@ -922,7 +922,7 @@ static int httpauth_ready(ha_request_t* rq, int ofd) /* We send a ready banner to our client */ - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) return httpauth_error(rq, ofd, HA_CRITERROR); else @@ -1072,7 +1072,7 @@ static int httpauth_processor(int ifd, int ofd) r = httpauth_read(&rq, ifd); - if(ha_buferr(&buf)) + if(CHECK_RBUF(&rq)) r = HA_CRITERROR; if(r < 0) @@ -1112,7 +1112,7 @@ static int httpauth_processor(int ifd, int ofd) break; }; - if(ha_buferr(&buf)) + if(CHECK_RBUF(&rq)) r = HA_CRITERROR; if(r < 0) diff --git a/daemon/httpauthd.h b/daemon/httpauthd.h index 1067d8d..a27dcc6 100644 --- a/daemon/httpauthd.h +++ b/daemon/httpauthd.h @@ -201,6 +201,7 @@ int ha_confint(const char* name, const char* conf, int min, int max, int* value) void ha_message(const ha_request_t* rq, int level, const char* msg, ...); void ha_messagex(const ha_request_t* rq, int level, const char* msg, ...); +void ha_memerr(const ha_request_t* rq); /* ----------------------------------------------------------------------- diff --git a/daemon/ldap.c b/daemon/ldap.c index e3f6a5f..a302d3d 100644 --- a/daemon/ldap.c +++ b/daemon/ldap.c @@ -284,7 +284,7 @@ static int parse_ldap_ha1(const ha_request_t* rq, struct berval* bv, unsigned ch } } - return ha_buferr(rq->buf) ? HA_CRITERROR : HA_FALSE; + return CHECK_RBUF(rq) ? HA_CRITERROR : HA_FALSE; } static int validate_ldap_password(const ha_request_t* rq, ldap_context_t* ctx, LDAP* ld, diff --git a/daemon/misc.c b/daemon/misc.c index 7ab8147..c671276 100644 --- a/daemon/misc.c +++ b/daemon/misc.c @@ -17,6 +17,11 @@ extern pthread_mutex_t g_mutex; * Error Handling */ +void ha_memerr(const ha_request_t* rq) +{ + ha_messagex(rq, LOG_CRIT, "out of memory"); +} + const char kMsgDelimiter[] = ": "; #define MAX_MSGLEN 128 diff --git a/daemon/mysql.c b/daemon/mysql.c index b6885b0..df2f8e2 100644 --- a/daemon/mysql.c +++ b/daemon/mysql.c @@ -131,7 +131,7 @@ static int dec_mysql_binary(const ha_request_t* rq, const char* enc, return HA_OK; } - return ha_buferr(rq->buf) ? HA_CRITERROR : HA_FALSE; + return CHECK_RBUF(rq) ? HA_CRITERROR : HA_FALSE; } static int validate_ha1(ha_request_t* rq, mysql_context_t* ctx, const char* user, diff --git a/daemon/ntlm.c b/daemon/ntlm.c index ab6e5e4..8e1aa20 100644 --- a/daemon/ntlm.c +++ b/daemon/ntlm.c @@ -406,8 +406,8 @@ int ntlm_auth_ntlm(ha_request_t* rq, ntlm_context_t* ctx, void* key, ha_bufenc64(rq->buf, (unsigned char*)&msg, sizeof(msg)); } - if(ha_buferr(rq->buf)) - RETURN(HA_FALSE); + if(CHECK_RBUF(rq)) + RETURN(HA_CRITERROR); /* * TODO: Our callers need to be able to keep alive @@ -513,7 +513,7 @@ int ntlm_auth_ntlm(ha_request_t* rq, ntlm_context_t* ctx, void* key, finally: - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) ret = HA_CRITERROR; if(conn) @@ -759,7 +759,7 @@ int ntlm_process(ha_request_t* rq) { ha_bufmcat(rq->buf, HA_PREFIX_BASIC, "realm=\"", rq->context->realm, "\"", NULL); - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) return HA_CRITERROR; ha_addheader(rq, "WWW-Authenticate", ha_bufdata(rq->buf)); diff --git a/daemon/pgsql.c b/daemon/pgsql.c index 6ed5658..ce3d3b3 100644 --- a/daemon/pgsql.c +++ b/daemon/pgsql.c @@ -142,7 +142,7 @@ static int dec_pgsql_binary(const ha_request_t* rq, const char* enc, return HA_OK; } - return ha_buferr(rq->buf) ? HA_CRITERROR : HA_FALSE; + return CHECK_RBUF(rq) ? HA_CRITERROR : HA_FALSE; } static int validate_ha1(ha_request_t* rq, pgsql_context_t* ctx, const char* user, diff --git a/daemon/simple.c b/daemon/simple.c index fca0e28..b37922e 100644 --- a/daemon/simple.c +++ b/daemon/simple.c @@ -142,7 +142,7 @@ static int validate_digest(ha_request_t* rq, const char* user, digest_context_t* fclose(f); - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) return HA_CRITERROR; return ret; @@ -208,7 +208,7 @@ static int validate_basic(ha_request_t* rq, const char* user, const char* passwo ha_lock(NULL); /* Check the password */ - t2 = (const char*)crypt(password, t); + t2 = (char*)crypt(password, t); ha_unlock(NULL); @@ -246,13 +246,13 @@ static int validate_basic(ha_request_t* rq, const char* user, const char* passwo break; } - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) break; } fclose(f); - if(ha_buferr(rq->buf)) + if(CHECK_RBUF(rq)) return HA_CRITERROR; return ret; diff --git a/daemon/usuals.h b/daemon/usuals.h index 020db4a..b97c85d 100644 --- a/daemon/usuals.h +++ b/daemon/usuals.h @@ -30,6 +30,16 @@ #define RETURN(x) { ret = (x); goto finally; } +/* + * To be used like this: + * if(CHECK_BUF(b)) + * return HA_CRITERROR; + */ + +#define CHECK_BUF(b) (ha_buferr(b) ? (ha_memerr(NULL), 1) : 0) +#define CHECK_RBUF(rq) (ha_buferr((rq)->buf) ? (ha_memerr(rq), 1) : 0) + + #ifdef _DEBUG #include "assert.h" #define ASSERT assert |