Commit 0f5f608d authored by Nils Goroll's avatar Nils Goroll

avoid duplicated logic and safe error handling

this avoids a potential panic for an out of workspace condition.

Also, we move error handling to a place where it is much simpler
parent 0364aba1
...@@ -1160,36 +1160,22 @@ vped_close_vdp(struct req *req, int skip, const struct vdp *vdp) ...@@ -1160,36 +1160,22 @@ vped_close_vdp(struct req *req, int skip, const struct vdp *vdp)
vdc->nxt = nxt; vdc->nxt = nxt;
} }
static int static void
push_vdps(struct req *req, struct nexus_gzip *gz, int obj_gzipped) push_vdps(struct req *req, struct vped_gzgz_priv *vgzgz, struct nexus_gzip *gz)
{ {
struct vped_gzgz_priv *vgzgz; if (vgzgz != NULL) {
AZ(gz);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(req->wrk, WORKER_MAGIC);
if (gz->is && obj_gzipped && !(req->res_mode & RES_ESI)) {
/* A gzip'ed include which is not ESI processed */
VSLdbg(req, "push_vdps: pushing gzgz");
if ((vgzgz = WS_Alloc(req->ws, sizeof(*vgzgz))) == NULL) {
VSLb(req->vsl, SLT_Error,
"Insufficient workspace for ESI gzip data");
return (-1);
}
INIT_OBJ(vgzgz, VPED_GZGZ_PRIV_MAGIC);
vgzgz->gz = gz;
AZ(VDP_Push(req, &vped_gzgz, vgzgz)); AZ(VDP_Push(req, &vped_gzgz, vgzgz));
} }
else if (gz->is && !obj_gzipped) { else if (gz != NULL) {
VSLdbg(req, "push_vdps: pushing pretend_gz"); AZ(vgzgz);
/* Non-Gzip'ed include in gzip'ed parent */
AZ(VDP_Push(req, &vped_pretend_gz, gz)); AZ(VDP_Push(req, &vped_pretend_gz, gz));
} }
// else just push to parent else {
AZ(vgzgz);
return (0); AZ(gz);
}
return;
} }
static void v_matchproto_(vtr_deliver_f) static void v_matchproto_(vtr_deliver_f)
...@@ -1200,6 +1186,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1200,6 +1186,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
struct bytes_tree *tree; struct bytes_tree *tree;
struct node *node, *parent; struct node *node, *parent;
struct nexus_gzip *gz; struct nexus_gzip *gz;
struct vped_gzgz_priv *vgzgz = NULL;
VSLdbgv(req, "vped_deliver: req=%p boc=%p wantbody=%d", req, boc, VSLdbgv(req, "vped_deliver: req=%p boc=%p wantbody=%d", req, boc,
wantbody); wantbody);
...@@ -1249,6 +1236,25 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1249,6 +1236,25 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
VDP_close(req); VDP_close(req);
return; return;
} }
vgzgz = WS_Alloc(req->ws, sizeof *vgzgz);
if (vgzgz == NULL) {
VSLb(req->vsl, SLT_Error,
"Insufficient workspace for ESI gzip data");
VDP_close(req);
return;
}
INIT_OBJ(vgzgz, VPED_GZGZ_PRIV_MAGIC);
vgzgz->gz = gz;
gz = NULL;
}
else if (gz->is && !obj_gzipped) {
AZ(vgzgz);
AN(gz);
}
else {
AZ(vgzgz);
gz = NULL;
} }
if (obj_final && !obj_esi && (pesi->flags & PF_CFG_BLOCK_FINAL) == 0) { if (obj_final && !obj_esi && (pesi->flags & PF_CFG_BLOCK_FINAL) == 0) {
...@@ -1257,7 +1263,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1257,7 +1263,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
VDP_Push(req, &VDP_pesi_buf, pesi); VDP_Push(req, &VDP_pesi_buf, pesi);
AN(parent); AN(parent);
assert(parent->type == T_NEXUS); assert(parent->type == T_NEXUS);
AZ(push_vdps(req, gz, obj_gzipped)); push_vdps(req, vgzgz, gz);
AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req)); AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req));
(void)VDP_DeliverObj(req); (void)VDP_DeliverObj(req);
...@@ -1271,7 +1277,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1271,7 +1277,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
else if (obj_final && !obj_esi) { else if (obj_final && !obj_esi) {
VSLdbg(req, "vped_deliver: T_FINAL"); VSLdbg(req, "vped_deliver: T_FINAL");
AZ(push_vdps(req, gz, obj_gzipped)); push_vdps(req, vgzgz, gz);
AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req)); AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req));
node_mutate_prep(tree, node); node_mutate_prep(tree, node);
...@@ -1311,7 +1317,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1311,7 +1317,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
VSLdbg(req, "vped_deliver: T_SUBREQ"); VSLdbg(req, "vped_deliver: T_SUBREQ");
AZ(req->objcore->flags & OC_F_FINAL); AZ(req->objcore->flags & OC_F_FINAL);
AZ(push_vdps(req, gz, obj_gzipped)); push_vdps(req, vgzgz, gz);
AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req)); AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req));
node_mutate_prep(tree, node); node_mutate_prep(tree, node);
...@@ -1344,7 +1350,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody) ...@@ -1344,7 +1350,7 @@ vped_deliver(struct req *req, struct boc *boc, int wantbody)
VSLdbg(req, "vped_deliver: ESI"); VSLdbg(req, "vped_deliver: ESI");
VDP_Push(req, &VDP_pesi_buf, pesi); VDP_Push(req, &VDP_pesi_buf, pesi);
AZ(push_vdps(req, gz, obj_gzipped)); push_vdps(req, vgzgz, gz);
AN(parent); AN(parent);
AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req)); AZ(VDP_Push(req, &vped_to_parent, parent->nexus.req));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment