Mercurial > urweb
changeset 1762:a6eab6820b37
Lance Hepler's fix to configure.ac; small refactor of fastcgi.c to avoid undefined behavior
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 13 May 2012 17:41:21 -0400 (2012-05-13) |
parents | f8ddaa296115 |
children | 22858505bb2d |
files | configure configure.ac src/c/fastcgi.c |
diffstat | 3 files changed, 17 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/configure Sun May 13 14:27:29 2012 -0400 +++ b/configure Sun May 13 17:41:21 2012 -0400 @@ -3445,7 +3445,6 @@ # automake 1.12 requires this, but automake 1.11 doesn't recognize it - # expand $ac_aux_dir to an absolute path am_aux_dir=`cd $ac_aux_dir && pwd`
--- a/configure.ac Sun May 13 14:27:29 2012 -0400 +++ b/configure.ac Sun May 13 17:41:21 2012 -0400 @@ -3,8 +3,7 @@ AC_USE_SYSTEM_EXTENSIONS # automake 1.12 requires this, but automake 1.11 doesn't recognize it -m4_pattern_allow([AM_PROG_AR]) -AM_PROG_AR +m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) AM_INIT_AUTOMAKE([-Wall -Werror foreign no-define]) AC_PROG_CC()
--- a/src/c/fastcgi.c Sun May 13 14:27:29 2012 -0400 +++ b/src/c/fastcgi.c Sun May 13 17:41:21 2012 -0400 @@ -40,7 +40,7 @@ } FCGI_Output; typedef struct { - char buf[sizeof(FCGI_Record) + 255]; + FCGI_Record r; int available, used, sock; } FCGI_Input; @@ -76,32 +76,28 @@ return uw_really_send(o->sock, &o->r, sizeof(o->r) - 65535 + contentLength); } -#define LATEST(i) ((FCGI_Record *)(i->buf + i->used)) +static FCGI_Record *fastcgi_recv(FCGI_Input *i) { + if (i->used > 0) { + memmove((void*)&i->r, (void*)&i->r + i->used, i->available - i->used); + i->available -= i->used; + i->used = 0; + } -static FCGI_Record *fastcgi_recv(FCGI_Input *i) { while (1) { ssize_t n; - if (i->available >= i->used + sizeof(FCGI_Record) - 65535 - && i->available >= i->used + sizeof(FCGI_Record) - 65535 - + ((LATEST(i)->contentLengthB1 << 8) | LATEST(i)->contentLengthB0) - + LATEST(i)->paddingLength) { - FCGI_Record *r = LATEST(i); - - i->used += sizeof(FCGI_Record) - 65535 - + ((LATEST(i)->contentLengthB1 << 8) | LATEST(i)->contentLengthB0) - + LATEST(i)->paddingLength; + if (i->available >= sizeof(FCGI_Record) - 65535 + && i->available >= sizeof(FCGI_Record) - 65535 + + ((i->r.contentLengthB1 << 8) | i->r.contentLengthB0) + + i->r.paddingLength) { + i->used = sizeof(FCGI_Record) - 65535 + + ((i->r.contentLengthB1 << 8) | i->r.contentLengthB0) + + i->r.paddingLength; - return r; + return &i->r; } - if (i->used > 0) { - memmove(i->buf, i->buf + i->used, i->available - i->used); - i->available -= i->used; - i->used = 0; - } - - n = recv(i->sock, i->buf + i->available, sizeof(i->buf) - i->available, 0); + n = recv(i->sock, (void*)&i->r + i->available, sizeof(i->r) - i->available, 0); if (n <= 0) return NULL;