[sheepdog] [PATCH stable-0.7 1/5] ops: add NULL check of req->op
Hitoshi Mitake
mitake.hitoshi at lab.ntt.co.jp
Mon Feb 24 07:06:22 CET 2014
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
req->op can be NULL when the requested opcode is invalid. It's safe
to add NULL checks before accessing req->op in ops.c.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
sheep/ops.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/sheep/ops.c b/sheep/ops.c
index d6ee016..5af516d 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -1355,47 +1355,50 @@ const struct sd_op_template *get_sd_op(uint8_t opcode)
const char *op_name(const struct sd_op_template *op)
{
+ if (op == NULL)
+ return "(invalid opcode)";
+
return op->name;
}
bool is_cluster_op(const struct sd_op_template *op)
{
- return op->type == SD_OP_TYPE_CLUSTER;
+ return op != NULL && op->type == SD_OP_TYPE_CLUSTER;
}
bool is_local_op(const struct sd_op_template *op)
{
- return op->type == SD_OP_TYPE_LOCAL;
+ return op != NULL && op->type == SD_OP_TYPE_LOCAL;
}
bool is_peer_op(const struct sd_op_template *op)
{
- return op->type == SD_OP_TYPE_PEER;
+ return op != NULL && op->type == SD_OP_TYPE_PEER;
}
bool is_gateway_op(const struct sd_op_template *op)
{
- return op->type == SD_OP_TYPE_GATEWAY;
+ return op != NULL && op->type == SD_OP_TYPE_GATEWAY;
}
bool is_force_op(const struct sd_op_template *op)
{
- return !!op->force;
+ return op != NULL && op->force;
}
bool is_logging_op(const struct sd_op_template *op)
{
- return !!op->is_admin_op;
+ return op != NULL && op->is_admin_op;
}
bool has_process_work(const struct sd_op_template *op)
{
- return !!op->process_work;
+ return op != NULL && !!op->process_work;
}
bool has_process_main(const struct sd_op_template *op)
{
- return !!op->process_main;
+ return op != NULL && !!op->process_main;
}
void do_process_work(struct work *work)
--
1.7.10.4
More information about the sheepdog
mailing list