In this commit, we validate the arguments as early as possible. There is no functional change.
Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvara...@ericsson.com> --- tipc/bearer.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/tipc/bearer.c b/tipc/bearer.c index d6f1edf5b4c5..c3494e96d3e3 100644 --- a/tipc/bearer.c +++ b/tipc/bearer.c @@ -331,14 +331,6 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname))) return err; - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) { - fprintf(stderr, "error, message initialisation failed\n"); - return -1; - } - - nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER); - mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname); - if (strcmp(media, "udp") == 0) { if (help_flag) { cmd_bearer_disable_udp_help(cmdl); @@ -353,6 +345,15 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd, fprintf(stderr, "error, invalid media type \"%s\"\n", media); return -EINVAL; } + + if (!(nlh = msg_init(buf, TIPC_NL_BEARER_DISABLE))) { + fprintf(stderr, "error, message initialisation failed\n"); + return -1; + } + + nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER); + mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname); + mnl_attr_nest_end(nlh, nest); return msg_doit(nlh, NULL, NULL); @@ -424,6 +425,15 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; + if (!(opt = get_opt(opts, "media"))) { + fprintf(stderr, "error, missing media\n"); + return -EINVAL; + } + media = opt->val; + + if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname))) + return err; + if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) { fprintf(stderr, "error, message initialisation failed\n"); return -1; @@ -434,15 +444,6 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd, mnl_attr_put_u32(nlh, prop, val); mnl_attr_nest_end(nlh, props); - if (!(opt = get_opt(opts, "media"))) { - fprintf(stderr, "error, missing media\n"); - return -EINVAL; - } - media = opt->val; - - if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname))) - return err; - mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname); if (strcmp(media, "udp") == 0) { @@ -559,11 +560,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if (parse_opts(opts, cmdl) < 0) return -EINVAL; - if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { - fprintf(stderr, "error, message initialisation failed\n"); - return -1; - } - if (!(opt = get_opt(opts, "media"))) { fprintf(stderr, "error, missing media\n"); return -EINVAL; @@ -573,9 +569,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname))) return err; - attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER); - mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname); - if (strcmp(media, "udp") == 0) { if (help_flag) { cmd_bearer_get_udp_help(cmdl); @@ -590,6 +583,14 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd, fprintf(stderr, "error, invalid media type \"%s\"\n", media); return -EINVAL; } + + if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) { + fprintf(stderr, "error, message initialisation failed\n"); + return -1; + } + + attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER); + mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname); mnl_attr_nest_end(nlh, attrs); return msg_doit(nlh, bearer_get_cb, &prop); -- 2.1.4 ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e _______________________________________________ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion