# HG changeset patch # User Adam Chlipala # Date 1381430923 14400 # Node ID 22b44fe822bff3b893e9fab5cfffcd813da52677 # Parent fdafa3f92e4043227dd475634c3be4556498dfe0 Take proper account of signatures changing during page generation diff -r fdafa3f92e40 -r 22b44fe822bf src/c/urweb.c --- a/src/c/urweb.c Mon Oct 07 14:08:53 2013 +0400 +++ b/src/c/urweb.c Thu Oct 10 14:48:43 2013 -0400 @@ -471,6 +471,8 @@ int amInitializing; char error_message[ERROR_BUF_LEN]; + + int usedSig, needsResig; }; size_t uw_headers_max = SIZE_MAX; @@ -546,6 +548,9 @@ ctx->amInitializing = 0; + ctx->usedSig = 0; + ctx->needsResig = 0; + return ctx; } @@ -624,6 +629,8 @@ ctx->queryString = NULL; ctx->nextId = 0; ctx->amInitializing = 0; + ctx->usedSig = 0; + ctx->needsResig = 0; } void uw_reset_keep_request(uw_context ctx) { @@ -3083,6 +3090,11 @@ return NULL; } +static void set_cookie(uw_context ctx) { + if (ctx->usedSig) + ctx->needsResig = 1; +} + uw_unit uw_Basis_set_cookie(uw_context ctx, uw_Basis_string prefix, uw_Basis_string c, uw_Basis_string v, uw_Basis_time *expires, uw_Basis_bool secure) { uw_write_header(ctx, "Set-Cookie: "); uw_write_header(ctx, c); @@ -3105,6 +3117,7 @@ if (secure) uw_write_header(ctx, "; secure"); uw_write_header(ctx, "\r\n"); + set_cookie(ctx); return uw_unit_v; } @@ -3115,6 +3128,7 @@ uw_write_header(ctx, "=; path="); uw_write_header(ctx, prefix); uw_write_header(ctx, "; " THE_PAST "\r\n"); + set_cookie(ctx); return uw_unit_v; } @@ -3192,8 +3206,32 @@ static const char begin_xhtml[] = "\n\n"; +extern int uw_hash_blocksize; + +static const char sig_intro[] = "needsResig) { + sig = find_sig(ctx->page.start); + if (sig) { + char *realsig = ctx->app->cookie_sig(ctx); + + do { + memcpy(sig, realsig, 2*uw_hash_blocksize); + sig = find_sig(sig); + } while (sig); + } + } } @@ -3561,8 +3611,6 @@ return s ? s : ""; } -extern int uw_hash_blocksize; - uw_Basis_string uw_Basis_makeSigString(uw_context ctx, uw_Basis_string sig) { uw_Basis_string r = uw_malloc(ctx, 2 * uw_hash_blocksize + 1); int i; @@ -3591,6 +3639,7 @@ } uw_Basis_string uw_Basis_sigString(uw_context ctx, uw_unit u) { + ctx->usedSig = 1; return ctx->app->cookie_sig(ctx); }