-const char parsers_rcs[] = "$Id: parsers.c,v 1.92 2007/03/05 13:25:32 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.93 2007/03/20 15:21:44 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*
* Revisions :
* $Log: parsers.c,v $
+ * Revision 1.93 2007/03/20 15:21:44 fabiankeil
+ * - Use dedicated header filter actions instead of abusing "filter".
+ * Replace "filter-client-headers" and "filter-client-headers"
+ * with "server-header-filter" and "client-header-filter".
+ * - Remove filter_client_header() and filter_client_header(),
+ * filter_header() now checks the shiny new
+ * CSP_FLAG_CLIENT_HEADER_PARSING_DONE flag instead.
+ *
* Revision 1.92 2007/03/05 13:25:32 fabiankeil
* - Cosmetical changes for LOG_LEVEL_RE_FILTER messages.
* - Handle "Cookie:" and "Connection:" headers a bit smarter
char *cur; /* Current iob position (to keep the original
* iob->cur unmodified if we return early) */
size_t bufsize; /* allocated size of the new buffer */
+ size_t old_size; /* Content size before decompression */
size_t skip_size; /* Number of bytes at the beginning of the iob
that we should NOT decompress. */
int status; /* return status of the inflate() call */
bufsize = csp->iob->size;
skip_size = (size_t)(csp->iob->cur - csp->iob->buf);
+ old_size = (size_t)(csp->iob->eod - csp->iob->cur);
cur = csp->iob->cur;
skip_bytes = *cur++;
skip_bytes = *cur++ << 8;
- assert(skip_bytes == *csp->iob->cur-2 + ((*csp->iob->cur-1) << 8));
+ assert(skip_bytes == *csp->iob->cur - 2 + ((*csp->iob->cur - 1) << 8));
/*
* The number of bytes to skip should be positive
/* Skip the filename if necessary. */
if (flags & 0x08)
{
- /* A null-terminated string follows. */
- while (*cur++);
+ /* A null-terminated string is supposed to follow. */
+ while (*cur++ && (cur < csp->iob->eod));
+
}
/* Skip the comment if necessary. */
if (flags & 0x10)
{
- while (*cur++);
+ /* A null-terminated string is supposed to follow. */
+ while (*cur++ && (cur < csp->iob->eod));
}
/* Skip the CRC if necessary. */
{
cur += 2;
}
+
+ if (cur >= csp->iob->eod)
+ {
+ /*
+ * If the current position pointer reached or passed
+ * the buffer end, we were obviously tricked to skip
+ * too much.
+ */
+ log_error (LOG_LEVEL_ERROR,
+ "Malformed gzip header detected. Aborting decompression.");
+ return JB_ERR_COMPRESS;
+ }
}
}
else if (csp->content_type & CT_DEFLATE)
&& (csp->iob->cur <= csp->iob->eod)
&& (csp->iob->eod <= csp->iob->buf + csp->iob->size))
{
- char t = csp->iob->cur[100];
- csp->iob->cur[100] = '\0';
- /*
- * XXX: The debug level should be lowered
- * before the next stable release.
- */
- log_error(LOG_LEVEL_INFO, "Sucessfully decompressed: %s", csp->iob->cur);
- csp->iob->cur[100] = t;
- return JB_ERR_OK;
+ const size_t new_size = (size_t)(csp->iob->eod - csp->iob->cur);
+ if (new_size > 0)
+ {
+ log_error(LOG_LEVEL_RE_FILTER,
+ "Decompression successful. Old size: %d, new size: %d.",
+ old_size, new_size);
+ }
+ else
+ {
+ /* zlib thinks this is OK, so lets do the same. */
+ log_error(LOG_LEVEL_INFO, "Decompression didn't result in any content.");
+ }
}
else
{
return JB_ERR_COMPRESS;
}
+ return JB_ERR_OK;
+
}
#endif /* defined(FEATURE_ZLIB) */