Skip to content

Commit 52e6887

Browse files
committed
expr parse fail should hide conditional content
these are neither true or false, the enclosing content should not be printed git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1934852 13f79535-47bb-0310-9956-ffa450edef68
1 parent 80f3a18 commit 52e6887

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎changes-entries/includes-error.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_include: Don't print any of if/elsif/else content when
2+
a conditional evaluation returns an error. [Eric Covener]

‎modules/filters/mod_include.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,6 +2329,8 @@ static apr_status_t handle_if(include_ctx_t *ctx, ap_filter_t *f,
23292329

23302330
if (ctx->argc != 1) {
23312331
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2332+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2333+
ctx->flags |= SSI_FLAG_COND_ERROR;
23322334
return APR_SUCCESS;
23332335
}
23342336

@@ -2338,13 +2340,17 @@ static apr_status_t handle_if(include_ctx_t *ctx, ap_filter_t *f,
23382340
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01354) "unknown parameter \"%s\" "
23392341
"to tag if in %s", tag, r->filename);
23402342
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2343+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2344+
ctx->flags |= SSI_FLAG_COND_ERROR;
23412345
return APR_SUCCESS;
23422346
}
23432347

23442348
if (!expr) {
23452349
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01355) "missing expr value for if "
23462350
"element in %s", r->filename);
23472351
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2352+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2353+
ctx->flags |= SSI_FLAG_COND_ERROR;
23482354
return APR_SUCCESS;
23492355
}
23502356

@@ -2356,6 +2362,8 @@ static apr_status_t handle_if(include_ctx_t *ctx, ap_filter_t *f,
23562362
expr_ret = parse_ap_expr(ctx, expr, &was_error);
23572363

23582364
if (was_error) {
2365+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2366+
ctx->flags |= SSI_FLAG_COND_ERROR;
23592367
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
23602368
return APR_SUCCESS;
23612369
}
@@ -2401,6 +2409,8 @@ static apr_status_t handle_elif(include_ctx_t *ctx, ap_filter_t *f,
24012409

24022410
if (ctx->argc != 1) {
24032411
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2412+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2413+
ctx->flags |= SSI_FLAG_COND_ERROR;
24042414
return APR_SUCCESS;
24052415
}
24062416

@@ -2410,13 +2420,17 @@ static apr_status_t handle_elif(include_ctx_t *ctx, ap_filter_t *f,
24102420
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01358) "unknown parameter \"%s\" "
24112421
"to tag if in %s", tag, r->filename);
24122422
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2423+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2424+
ctx->flags |= SSI_FLAG_COND_ERROR;
24132425
return APR_SUCCESS;
24142426
}
24152427

24162428
if (!expr) {
24172429
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01359) "missing expr in elif "
24182430
"statement: %s", r->filename);
24192431
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
2432+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2433+
ctx->flags |= SSI_FLAG_COND_ERROR;
24202434
return APR_SUCCESS;
24212435
}
24222436

@@ -2434,6 +2448,8 @@ static apr_status_t handle_elif(include_ctx_t *ctx, ap_filter_t *f,
24342448
expr_ret = parse_ap_expr(ctx, expr, &was_error);
24352449

24362450
if (was_error) {
2451+
ctx->flags &= SSI_FLAG_CLEAR_PRINT_COND;
2452+
ctx->flags |= SSI_FLAG_COND_ERROR;
24372453
SSI_CREATE_ERROR_BUCKET(ctx, f, bb);
24382454
return APR_SUCCESS;
24392455
}
@@ -2480,6 +2496,11 @@ static apr_status_t handle_else(include_ctx_t *ctx, ap_filter_t *f,
24802496

24812497
DEBUG_DUMP_COND(ctx, " else");
24822498

2499+
/* Don't toggle printing if there was an expression evaluation error */
2500+
if (ctx->flags & SSI_FLAG_COND_ERROR) {
2501+
return APR_SUCCESS;
2502+
}
2503+
24832504
if (ctx->flags & SSI_FLAG_COND_TRUE) {
24842505
ctx->flags &= SSI_FLAG_CLEAR_PRINTING;
24852506
}
@@ -2519,6 +2540,7 @@ static apr_status_t handle_endif(include_ctx_t *ctx, ap_filter_t *f,
25192540
DEBUG_DUMP_COND(ctx, "endif");
25202541

25212542
ctx->flags |= (SSI_FLAG_PRINTING | SSI_FLAG_COND_TRUE);
2543+
ctx->flags &= ~SSI_FLAG_COND_ERROR;
25222544

25232545
return APR_SUCCESS;
25242546
}

‎modules/filters/mod_include.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#define SSI_FLAG_COND_TRUE (1<<1) /* Conditional eval'd to true. */
5858
#define SSI_FLAG_SIZE_IN_BYTES (1<<2) /* Sizes displayed in bytes. */
5959
#define SSI_FLAG_NO_EXEC (1<<3) /* No Exec in current context. */
60+
#define SSI_FLAG_COND_ERROR (1<<4) /* Conditional evaluation was in error */
6061

6162
#define SSI_FLAG_SIZE_ABBREV (~(SSI_FLAG_SIZE_IN_BYTES))
6263
#define SSI_FLAG_CLEAR_PRINT_COND (~((SSI_FLAG_PRINTING) | \

0 commit comments

Comments
 (0)