17bfed
diff --git a/modules/filters/mod_sed.c b/modules/filters/mod_sed.c
17bfed
index 8595e41..9b99a6b 100644
17bfed
--- a/modules/filters/mod_sed.c
17bfed
+++ b/modules/filters/mod_sed.c
17bfed
@@ -59,7 +59,7 @@ typedef struct sed_filter_ctxt
17bfed
 module AP_MODULE_DECLARE_DATA sed_module;
17bfed
 
17bfed
 /* This function will be call back from libsed functions if there is any error
17bfed
- * happend during execution of sed scripts
17bfed
+ * happened during execution of sed scripts
17bfed
  */
17bfed
 static apr_status_t log_sed_errf(void *data, const char *error)
17bfed
 {
17bfed
@@ -276,7 +276,7 @@ static apr_status_t sed_response_filter(ap_filter_t *f,
17bfed
                                         apr_bucket_brigade *bb)
17bfed
 {
17bfed
     apr_bucket *b;
17bfed
-    apr_status_t status;
17bfed
+    apr_status_t status = APR_SUCCESS;
17bfed
     sed_config *cfg = ap_get_module_config(f->r->per_dir_config,
17bfed
                                            &sed_module);
17bfed
     sed_filter_ctxt *ctx = f->ctx;
17bfed
@@ -301,9 +301,9 @@ static apr_status_t sed_response_filter(ap_filter_t *f,
17bfed
              return status;
17bfed
         ctx = f->ctx;
17bfed
         apr_table_unset(f->r->headers_out, "Content-Length");
17bfed
-    }
17bfed
 
17bfed
-    ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
17bfed
+        ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
17bfed
+    }
17bfed
 
17bfed
     /* Here is the main logic. Iterate through all the buckets, read the
17bfed
      * content of the bucket, call sed_eval_buffer on the data.
17bfed
@@ -325,63 +325,52 @@ static apr_status_t sed_response_filter(ap_filter_t *f,
17bfed
      * in sed's internal buffer which can't be flushed until new line
17bfed
      * character is arrived.
17bfed
      */
17bfed
-    for (b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb);) {
17bfed
-        const char *buf = NULL;
17bfed
-        apr_size_t bytes = 0;
17bfed
+    while (!APR_BRIGADE_EMPTY(bb)) {
17bfed
+        b = APR_BRIGADE_FIRST(bb);
17bfed
         if (APR_BUCKET_IS_EOS(b)) {
17bfed
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
17bfed
             /* Now clean up the internal sed buffer */
17bfed
             sed_finalize_eval(&ctx->eval, ctx);
17bfed
             status = flush_output_buffer(ctx);
17bfed
             if (status != APR_SUCCESS) {
17bfed
-                clear_ctxpool(ctx);
17bfed
-                return status;
17bfed
+                break;
17bfed
             }
17bfed
+            /* Move the eos bucket to ctx->bb brigade */
17bfed
             APR_BUCKET_REMOVE(b);
17bfed
-            /* Insert the eos bucket to ctx->bb brigade */
17bfed
             APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
17bfed
-            b = b1;
17bfed
         }
17bfed
         else if (APR_BUCKET_IS_FLUSH(b)) {
17bfed
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
17bfed
-            APR_BUCKET_REMOVE(b);
17bfed
             status = flush_output_buffer(ctx);
17bfed
             if (status != APR_SUCCESS) {
17bfed
-                clear_ctxpool(ctx);
17bfed
-                return status;
17bfed
+                break;
17bfed
             }
17bfed
+            /* Move the flush bucket to ctx->bb brigade */
17bfed
+            APR_BUCKET_REMOVE(b);
17bfed
             APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
17bfed
-            b = b1;
17bfed
-        }
17bfed
-        else if (APR_BUCKET_IS_METADATA(b)) {
17bfed
-            b = APR_BUCKET_NEXT(b);
17bfed
         }
17bfed
-        else if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ)
17bfed
-                 == APR_SUCCESS) {
17bfed
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
17bfed
-            status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
17bfed
-            if (status != APR_SUCCESS) {
17bfed
-                clear_ctxpool(ctx);
17bfed
-                return status;
17bfed
+        else {
17bfed
+            if (!APR_BUCKET_IS_METADATA(b)) {
17bfed
+                const char *buf = NULL;
17bfed
+                apr_size_t bytes = 0;
17bfed
+
17bfed
+                status = apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ);
17bfed
+                if (status == APR_SUCCESS) {
17bfed
+                    status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
17bfed
+                }
17bfed
+                if (status != APR_SUCCESS) {
17bfed
+                    ap_log_rerror(APLOG_MARK, APLOG_ERR, status, f->r, APLOGNO(10394) "error evaluating sed on output");
17bfed
+                    break;
17bfed
+                }
17bfed
             }
17bfed
-            APR_BUCKET_REMOVE(b);
17bfed
             apr_bucket_delete(b);
17bfed
-            b = b1;
17bfed
-        }
17bfed
-        else {
17bfed
-            apr_bucket *b1 = APR_BUCKET_NEXT(b);
17bfed
-            APR_BUCKET_REMOVE(b);
17bfed
-            b = b1;
17bfed
         }
17bfed
     }
17bfed
-    apr_brigade_cleanup(bb);
17bfed
-    status = flush_output_buffer(ctx);
17bfed
-    if (status != APR_SUCCESS) {
17bfed
-        clear_ctxpool(ctx);
17bfed
-        return status;
17bfed
+    if (status == APR_SUCCESS) {
17bfed
+        status = flush_output_buffer(ctx);
17bfed
     }
17bfed
     if (!APR_BRIGADE_EMPTY(ctx->bb)) {
17bfed
-        status = ap_pass_brigade(f->next, ctx->bb);
17bfed
+        if (status == APR_SUCCESS) {
17bfed
+            status = ap_pass_brigade(f->next, ctx->bb);
17bfed
+        }
17bfed
         apr_brigade_cleanup(ctx->bb);
17bfed
     }
17bfed
     clear_ctxpool(ctx);
17bfed
@@ -432,7 +421,7 @@ static apr_status_t sed_request_filter(ap_filter_t *f,
17bfed
      * the buckets in bbinp and read the data from buckets and invoke
17bfed
      * sed_eval_buffer on the data. libsed will generate its output using
17bfed
      * sed_write_output which will add data in ctx->bb. Do it until it have
17bfed
-     * atleast one bucket in ctx->bb. At the end of data eos bucket
17bfed
+     * at least one bucket in ctx->bb. At the end of data eos bucket
17bfed
      * should be there.
17bfed
      *
17bfed
      * Once eos bucket is seen, then invoke sed_finalize_eval to clear the
17bfed
@@ -474,8 +463,10 @@ static apr_status_t sed_request_filter(ap_filter_t *f,
17bfed
             if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ)
17bfed
                      == APR_SUCCESS) {
17bfed
                 status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
17bfed
-                if (status != APR_SUCCESS)
17bfed
+                if (status != APR_SUCCESS) { 
17bfed
+                    ap_log_rerror(APLOG_MARK, APLOG_ERR, status, f->r, APLOGNO(10395) "error evaluating sed on input");
17bfed
                     return status;
17bfed
+                }
17bfed
                 flush_output_buffer(ctx);
17bfed
             }
17bfed
         }
17bfed
diff --git a/modules/filters/sed1.c b/modules/filters/sed1.c
17bfed
index 67a8d06..047f49b 100644
17bfed
--- a/modules/filters/sed1.c
17bfed
+++ b/modules/filters/sed1.c
17bfed
@@ -87,18 +87,20 @@ static void eval_errf(sed_eval_t *eval, const char *fmt, ...)
17bfed
 }
17bfed
 
17bfed
 #define INIT_BUF_SIZE 1024
17bfed
+#define MAX_BUF_SIZE 1024*8192
17bfed
 
17bfed
 /*
17bfed
  * grow_buffer
17bfed
  */
17bfed
-static void grow_buffer(apr_pool_t *pool, char **buffer,
17bfed
+static apr_status_t grow_buffer(apr_pool_t *pool, char **buffer,
17bfed
                         char **spend, apr_size_t *cursize,
17bfed
                         apr_size_t newsize)
17bfed
 {
17bfed
     char* newbuffer = NULL;
17bfed
     apr_size_t spendsize = 0;
17bfed
-    if (*cursize >= newsize)
17bfed
-        return;
17bfed
+    if (*cursize >= newsize) {
17bfed
+        return APR_SUCCESS;
17bfed
+    }
17bfed
     /* Avoid number of times realloc is called. It could cause huge memory
17bfed
      * requirement if line size is huge e.g 2 MB */
17bfed
     if (newsize < *cursize * 2) {
17bfed
@@ -107,6 +109,9 @@ static void grow_buffer(apr_pool_t *pool, char **buffer,
17bfed
 
17bfed
     /* Align it to 4 KB boundary */
17bfed
     newsize = (newsize  + ((1 << 12) - 1)) & ~((1 << 12) - 1);
17bfed
+    if (newsize > MAX_BUF_SIZE) { 
17bfed
+        return APR_ENOMEM;
17bfed
+    }
17bfed
     newbuffer = apr_pcalloc(pool, newsize);
17bfed
     if (*spend && *buffer && (*cursize > 0)) {
17bfed
         spendsize = *spend - *buffer;
17bfed
@@ -119,63 +124,77 @@ static void grow_buffer(apr_pool_t *pool, char **buffer,
17bfed
     if (spend != buffer) {
17bfed
         *spend = *buffer + spendsize;
17bfed
     }
17bfed
+    return APR_SUCCESS;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * grow_line_buffer
17bfed
  */
17bfed
-static void grow_line_buffer(sed_eval_t *eval, apr_size_t newsize)
17bfed
+static apr_status_t grow_line_buffer(sed_eval_t *eval, apr_size_t newsize)
17bfed
 {
17bfed
-    grow_buffer(eval->pool, &eval->linebuf, &eval->lspend,
17bfed
+    return grow_buffer(eval->pool, &eval->linebuf, &eval->lspend,
17bfed
                 &eval->lsize, newsize);
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * grow_hold_buffer
17bfed
  */
17bfed
-static void grow_hold_buffer(sed_eval_t *eval, apr_size_t newsize)
17bfed
+static apr_status_t grow_hold_buffer(sed_eval_t *eval, apr_size_t newsize)
17bfed
 {
17bfed
-    grow_buffer(eval->pool, &eval->holdbuf, &eval->hspend,
17bfed
+    return grow_buffer(eval->pool, &eval->holdbuf, &eval->hspend,
17bfed
                 &eval->hsize, newsize);
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * grow_gen_buffer
17bfed
  */
17bfed
-static void grow_gen_buffer(sed_eval_t *eval, apr_size_t newsize,
17bfed
+static apr_status_t grow_gen_buffer(sed_eval_t *eval, apr_size_t newsize,
17bfed
                             char **gspend)
17bfed
 {
17bfed
+    apr_status_t rc = 0;
17bfed
     if (gspend == NULL) {
17bfed
         gspend = &eval->genbuf;
17bfed
     }
17bfed
-    grow_buffer(eval->pool, &eval->genbuf, gspend,
17bfed
-                &eval->gsize, newsize);
17bfed
-    eval->lcomend = &eval->genbuf[71];
17bfed
+    rc = grow_buffer(eval->pool, &eval->genbuf, gspend,
17bfed
+                     &eval->gsize, newsize);
17bfed
+    if (rc == APR_SUCCESS) { 
17bfed
+        eval->lcomend = &eval->genbuf[71];
17bfed
+    }
17bfed
+    return rc;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * appendmem_to_linebuf
17bfed
  */
17bfed
-static void appendmem_to_linebuf(sed_eval_t *eval, const char* sz, apr_size_t len)
17bfed
+static apr_status_t appendmem_to_linebuf(sed_eval_t *eval, const char* sz, apr_size_t len)
17bfed
 {
17bfed
+    apr_status_t rc = 0;
17bfed
     apr_size_t reqsize = (eval->lspend - eval->linebuf) + len;
17bfed
     if (eval->lsize < reqsize) {
17bfed
-        grow_line_buffer(eval, reqsize);
17bfed
+        rc = grow_line_buffer(eval, reqsize);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
     }
17bfed
     memcpy(eval->lspend, sz, len);
17bfed
     eval->lspend += len;
17bfed
+    return APR_SUCCESS;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * append_to_linebuf
17bfed
  */
17bfed
-static void append_to_linebuf(sed_eval_t *eval, const char* sz,
17bfed
+static apr_status_t append_to_linebuf(sed_eval_t *eval, const char* sz,
17bfed
                               step_vars_storage *step_vars)
17bfed
 {
17bfed
     apr_size_t len = strlen(sz);
17bfed
     char *old_linebuf = eval->linebuf;
17bfed
+    apr_status_t rc = 0;
17bfed
     /* Copy string including null character */
17bfed
-    appendmem_to_linebuf(eval, sz, len + 1);
17bfed
+    rc = appendmem_to_linebuf(eval, sz, len + 1);
17bfed
+    if (rc != APR_SUCCESS) { 
17bfed
+        return rc;
17bfed
+    }
17bfed
     --eval->lspend; /* lspend will now point to NULL character */
17bfed
     /* Sync step_vars after a possible linebuf expansion */
17bfed
     if (step_vars && old_linebuf != eval->linebuf) {
17bfed
@@ -189,68 +208,84 @@ static void append_to_linebuf(sed_eval_t *eval, const char* sz,
17bfed
             step_vars->locs = step_vars->locs - old_linebuf + eval->linebuf;
17bfed
         }
17bfed
     }
17bfed
+    return APR_SUCCESS;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * copy_to_linebuf
17bfed
  */
17bfed
-static void copy_to_linebuf(sed_eval_t *eval, const char* sz,
17bfed
+static apr_status_t copy_to_linebuf(sed_eval_t *eval, const char* sz,
17bfed
                             step_vars_storage *step_vars)
17bfed
 {
17bfed
     eval->lspend = eval->linebuf;
17bfed
-    append_to_linebuf(eval, sz, step_vars);
17bfed
+    return append_to_linebuf(eval, sz, step_vars);
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * append_to_holdbuf
17bfed
  */
17bfed
-static void append_to_holdbuf(sed_eval_t *eval, const char* sz)
17bfed
+static apr_status_t append_to_holdbuf(sed_eval_t *eval, const char* sz)
17bfed
 {
17bfed
     apr_size_t len = strlen(sz);
17bfed
     apr_size_t reqsize = (eval->hspend - eval->holdbuf) + len + 1;
17bfed
+    apr_status_t rc = 0;
17bfed
     if (eval->hsize <= reqsize) {
17bfed
-        grow_hold_buffer(eval, reqsize);
17bfed
+        rc = grow_hold_buffer(eval, reqsize);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
     }
17bfed
     memcpy(eval->hspend, sz, len + 1);
17bfed
     /* hspend will now point to NULL character */
17bfed
     eval->hspend += len;
17bfed
+    return APR_SUCCESS;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * copy_to_holdbuf
17bfed
  */
17bfed
-static void copy_to_holdbuf(sed_eval_t *eval, const char* sz)
17bfed
+static apr_status_t copy_to_holdbuf(sed_eval_t *eval, const char* sz)
17bfed
 {
17bfed
     eval->hspend = eval->holdbuf;
17bfed
-    append_to_holdbuf(eval, sz);
17bfed
+    return append_to_holdbuf(eval, sz);
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * append_to_genbuf
17bfed
  */
17bfed
-static void append_to_genbuf(sed_eval_t *eval, const char* sz, char **gspend)
17bfed
+static apr_status_t append_to_genbuf(sed_eval_t *eval, const char* sz, char **gspend)
17bfed
 {
17bfed
     apr_size_t len = strlen(sz);
17bfed
     apr_size_t reqsize = (*gspend - eval->genbuf) + len + 1;
17bfed
+    apr_status_t rc = 0;
17bfed
     if (eval->gsize < reqsize) {
17bfed
-        grow_gen_buffer(eval, reqsize, gspend);
17bfed
+        rc = grow_gen_buffer(eval, reqsize, gspend);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
     }
17bfed
     memcpy(*gspend, sz, len + 1);
17bfed
     /* *gspend will now point to NULL character */
17bfed
     *gspend += len;
17bfed
+    return APR_SUCCESS;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
  * copy_to_genbuf
17bfed
  */
17bfed
-static void copy_to_genbuf(sed_eval_t *eval, const char* sz)
17bfed
+static apr_status_t copy_to_genbuf(sed_eval_t *eval, const char* sz)
17bfed
 {
17bfed
     apr_size_t len = strlen(sz);
17bfed
     apr_size_t reqsize = len + 1;
17bfed
+    apr_status_t rc = APR_SUCCESS;;
17bfed
     if (eval->gsize < reqsize) {
17bfed
-        grow_gen_buffer(eval, reqsize, NULL);
17bfed
+        rc = grow_gen_buffer(eval, reqsize, NULL);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
     }
17bfed
     memcpy(eval->genbuf, sz, len + 1);
17bfed
+    return rc;
17bfed
 }
17bfed
 
17bfed
 /*
17bfed
@@ -397,6 +432,7 @@ apr_status_t sed_eval_buffer(sed_eval_t *eval, const char *buf, apr_size_t bufsz
17bfed
     }
17bfed
 
17bfed
     while (bufsz) {
17bfed
+        apr_status_t rc = 0;
17bfed
         char *n;
17bfed
         apr_size_t llen;
17bfed
 
17bfed
@@ -411,7 +447,10 @@ apr_status_t sed_eval_buffer(sed_eval_t *eval, const char *buf, apr_size_t bufsz
17bfed
             break;
17bfed
         }
17bfed
 
17bfed
-        appendmem_to_linebuf(eval, buf, llen + 1);
17bfed
+        rc = appendmem_to_linebuf(eval, buf, llen + 1);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
         --eval->lspend;
17bfed
         /* replace new line character with NULL */
17bfed
         *eval->lspend = '\0';
17bfed
@@ -426,7 +465,10 @@ apr_status_t sed_eval_buffer(sed_eval_t *eval, const char *buf, apr_size_t bufsz
17bfed
 
17bfed
     /* Save the leftovers for later */
17bfed
     if (bufsz) {
17bfed
-        appendmem_to_linebuf(eval, buf, bufsz);
17bfed
+        apr_status_t rc = appendmem_to_linebuf(eval, buf, bufsz);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return rc;
17bfed
+        }
17bfed
     }
17bfed
 
17bfed
     return APR_SUCCESS;
17bfed
@@ -448,6 +490,7 @@ apr_status_t sed_finalize_eval(sed_eval_t *eval, void *fout)
17bfed
     /* Process leftovers */
17bfed
     if (eval->lspend > eval->linebuf) {
17bfed
         apr_status_t rv;
17bfed
+        apr_status_t rc = 0;
17bfed
 
17bfed
         if (eval->lreadyflag) {
17bfed
             eval->lreadyflag = 0;
17bfed
@@ -457,7 +500,10 @@ apr_status_t sed_finalize_eval(sed_eval_t *eval, void *fout)
17bfed
              * buffer is not a newline.
17bfed
              */
17bfed
             /* Assure space for NULL */
17bfed
-            append_to_linebuf(eval, "", NULL);
17bfed
+            rc = append_to_linebuf(eval, "", NULL);
17bfed
+            if (rc != APR_SUCCESS) { 
17bfed
+                return rc;
17bfed
+            }
17bfed
         }
17bfed
 
17bfed
         *eval->lspend = '\0';
17bfed
@@ -655,11 +701,15 @@ static apr_status_t dosub(sed_eval_t *eval, char *rhsbuf, int n,
17bfed
     sp = eval->genbuf;
17bfed
     rp = rhsbuf;
17bfed
     sp = place(eval, sp, lp, step_vars->loc1);
17bfed
+    if (sp == NULL) { 
17bfed
+        return APR_EGENERAL;
17bfed
+    }
17bfed
     while ((c = *rp++) != 0) {
17bfed
         if (c == '&') {
17bfed
             sp = place(eval, sp, step_vars->loc1, step_vars->loc2);
17bfed
-            if (sp == NULL)
17bfed
+            if (sp == NULL) {
17bfed
                 return APR_EGENERAL;
17bfed
+            }
17bfed
         }
17bfed
         else if (c == '\\') {
17bfed
             c = *rp++;
17bfed
@@ -675,13 +725,19 @@ static apr_status_t dosub(sed_eval_t *eval, char *rhsbuf, int n,
17bfed
             *sp++ = c;
17bfed
         if (sp >= eval->genbuf + eval->gsize) {
17bfed
             /* expand genbuf and set the sp appropriately */
17bfed
-            grow_gen_buffer(eval, eval->gsize + 1024, &sp);
17bfed
+            rv = grow_gen_buffer(eval, eval->gsize + 1024, &sp);
17bfed
+            if (rv != APR_SUCCESS) { 
17bfed
+                return rv;
17bfed
+            }
17bfed
         }
17bfed
     }
17bfed
     lp = step_vars->loc2;
17bfed
     step_vars->loc2 = sp - eval->genbuf + eval->linebuf;
17bfed
-    append_to_genbuf(eval, lp, &sp);
17bfed
-    copy_to_linebuf(eval, eval->genbuf, step_vars);
17bfed
+    rv = append_to_genbuf(eval, lp, &sp);
17bfed
+    if (rv != APR_SUCCESS) { 
17bfed
+        return rv;
17bfed
+    }
17bfed
+    rv = copy_to_linebuf(eval, eval->genbuf, step_vars);
17bfed
     return rv;
17bfed
 }
17bfed
 
17bfed
@@ -695,7 +751,10 @@ static char *place(sed_eval_t *eval, char *asp, char *al1, char *al2)
17bfed
     apr_size_t reqsize = (sp - eval->genbuf) + n + 1;
17bfed
 
17bfed
     if (eval->gsize < reqsize) {
17bfed
-        grow_gen_buffer(eval, reqsize, &sp);
17bfed
+        apr_status_t rc = grow_gen_buffer(eval, reqsize, &sp);
17bfed
+        if (rc != APR_SUCCESS) { 
17bfed
+            return NULL;
17bfed
+        }
17bfed
     }
17bfed
     memcpy(sp, al1, n);
17bfed
     return sp + n;
17bfed
@@ -750,7 +809,8 @@ static apr_status_t command(sed_eval_t *eval, sed_reptr_t *ipc,
17bfed
             }
17bfed
 
17bfed
             p1++;
17bfed
-            copy_to_linebuf(eval, p1, step_vars);
17bfed
+            rv = copy_to_linebuf(eval, p1, step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             eval->jflag++;
17bfed
             break;
17bfed
 
17bfed
@@ -760,21 +820,27 @@ static apr_status_t command(sed_eval_t *eval, sed_reptr_t *ipc,
17bfed
             break;
17bfed
 
17bfed
         case GCOM:
17bfed
-            copy_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
+            rv = copy_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             break;
17bfed
 
17bfed
         case CGCOM:
17bfed
-            append_to_linebuf(eval, "\n", step_vars);
17bfed
-            append_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
+            rv = append_to_linebuf(eval, "\n", step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
+            rv = append_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             break;
17bfed
 
17bfed
         case HCOM:
17bfed
-            copy_to_holdbuf(eval, eval->linebuf);
17bfed
+            rv = copy_to_holdbuf(eval, eval->linebuf);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             break;
17bfed
 
17bfed
         case CHCOM:
17bfed
-            append_to_holdbuf(eval, "\n");
17bfed
-            append_to_holdbuf(eval, eval->linebuf);
17bfed
+            rv = append_to_holdbuf(eval, "\n");
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
+            rv = append_to_holdbuf(eval, eval->linebuf);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             break;
17bfed
 
17bfed
         case ICOM:
17bfed
@@ -896,7 +962,8 @@ static apr_status_t command(sed_eval_t *eval, sed_reptr_t *ipc,
17bfed
                 if (rv != APR_SUCCESS)
17bfed
                     return rv;
17bfed
             }
17bfed
-            append_to_linebuf(eval, "\n", step_vars);
17bfed
+            rv = append_to_linebuf(eval, "\n", step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             eval->pending = ipc->next;
17bfed
             break;
17bfed
 
17bfed
@@ -970,9 +1037,12 @@ static apr_status_t command(sed_eval_t *eval, sed_reptr_t *ipc,
17bfed
             break;
17bfed
 
17bfed
         case XCOM:
17bfed
-            copy_to_genbuf(eval, eval->linebuf);
17bfed
-            copy_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
-            copy_to_holdbuf(eval, eval->genbuf);
17bfed
+            rv = copy_to_genbuf(eval, eval->linebuf);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
+            rv = copy_to_linebuf(eval, eval->holdbuf, step_vars);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
+            rv = copy_to_holdbuf(eval, eval->genbuf);
17bfed
+            if (rv != APR_SUCCESS) return rv;
17bfed
             break;
17bfed
 
17bfed
         case YCOM: