Instead of explicitly initializing variables to avoid compiler warnings,

add a default case to handle the situation when the variables are not
initialized.
Furthermore, abort() if the snmp agent passes an invalid option to the
bridge module. As the option (SET, GET, GETNEXT, COMMIT, ROLLBACK) is
determined by the snmp agent based on the operation requested by user,
this behaviour is unlikely to be abused as a source for a DoS, but if
ever hit will likely reveal a problem in the snmp agent or bridge
module.

Approved by:    bz (mentor)
This commit is contained in:
Shteryana Shopova 2006-12-09 20:58:26 +00:00
parent 0972edc076
commit 5b6598a8c2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=165046
3 changed files with 42 additions and 16 deletions

View File

@ -408,7 +408,6 @@ op_dot1d_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
bridge_update_addrs(bif) <= 0)
return (SNMP_ERR_NOSUCHNAME);
te = NULL; /* Make the compiler happy. */
switch (op) {
case SNMP_OP_GET:
if ((te = bridge_addrs_get(&val->var, sub, bif)) == NULL)
@ -426,6 +425,7 @@ op_dot1d_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
}
@ -548,7 +548,7 @@ op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct tp_entry *te = NULL;
struct tp_entry *te;
if (time(NULL) - address_list_age > bridge_get_data_maxage())
bridge_update_all_addrs();
@ -572,7 +572,8 @@ op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
ret = SNMP_ERR_NOERROR;

View File

@ -1096,7 +1096,7 @@ op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif = NULL;
struct bridge_if *bif;
if (time(NULL) - bridge_list_age > bridge_get_data_maxage())
bridge_update_all_ifs();
@ -1127,8 +1127,12 @@ op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
return (bridge_rollback_if_status(ctx, val, sub));
case SNMP_OP_COMMIT:
return (bridge_commit_if_status(val, sub));
default:
abort();
}
ret = SNMP_ERR_NOERROR;
@ -1161,8 +1165,8 @@ int
op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret = SNMP_ERR_NOERROR; /* Make the compiler happy. */
struct bridge_if *bif = NULL;
int ret;
struct bridge_if *bif;
if (time(NULL) - bridge_list_age > bridge_get_data_maxage())
bridge_update_all_ifs();
@ -1225,6 +1229,9 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
case LEAF_begemotBridgeStpHoldTime:
case LEAF_begemotBridgeStpForwardDelay:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == 0)
@ -1266,8 +1273,13 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
ret = SNMP_ERR_NOERROR;
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpProtocolSpecification:
val->v.integer = bif->prot_spec;
@ -1342,7 +1354,7 @@ int
op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
struct bridge_if *bif = NULL;
struct bridge_if *bif;
if (time(NULL) - bridge_list_age > bridge_get_data_maxage())
bridge_update_all_ifs();
@ -1398,6 +1410,9 @@ op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
switch (val->var.subs[sub - 1]) {

View File

@ -353,7 +353,6 @@ op_dot1d_base_port(struct snmp_context *c __unused, struct snmp_value *val,
bridge_update_memif(bif) <= 0)
return (SNMP_ERR_NOSUCHNAME);
bp = NULL; /* Make the compiler happy. */
switch (op) {
case SNMP_OP_GET:
if (val->var.len - sub != 1)
@ -382,6 +381,7 @@ op_dot1d_base_port(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
}
@ -421,8 +421,6 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
bridge_update_memif(bif) <= 0)
return (SNMP_ERR_NOSUCHNAME);
bp = NULL; /* Make the compiler happy. */
switch (op) {
case SNMP_OP_GET:
if (val->var.len - sub != 1)
@ -508,6 +506,9 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
ret = SNMP_ERR_NOERROR;
@ -564,7 +565,6 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
bridge_update_memif(bif) <= 0)
return (SNMP_ERR_NOSUCHNAME);
bp = NULL; /* Make the compiler happy. */
switch (op) {
case SNMP_OP_GET:
if (val->var.len - sub != 1)
@ -648,6 +648,9 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
switch (val->var.subs[sub - 1]) {
@ -688,7 +691,6 @@ op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
bridge_update_memif(bif) <= 0)
return (SNMP_ERR_NOSUCHNAME);
bp = NULL; /* Make the compiler happy. */
switch (op) {
case SNMP_OP_GET:
if (val->var.len - sub != 1)
@ -717,6 +719,7 @@ op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
}
@ -1122,7 +1125,7 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_port *bp = NULL;
struct bridge_port *bp;
const char *b_name;
if (time(NULL) - ports_list_age > bridge_get_data_maxage())
@ -1201,6 +1204,9 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
ret = SNMP_ERR_NOERROR;
@ -1245,7 +1251,7 @@ op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_port *bp = NULL;
struct bridge_port *bp;
const char *b_name;
if (time(NULL) - ports_list_age > bridge_get_data_maxage())
@ -1322,6 +1328,9 @@ op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
switch (val->var.subs[sub - 1]) {
@ -1352,7 +1361,7 @@ int
op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
struct bridge_port *bp = NULL;
struct bridge_port *bp;
if (time(NULL) - ports_list_age > bridge_get_data_maxage())
bridge_update_all_ports();
@ -1374,7 +1383,8 @@ op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
switch (val->var.subs[sub - 1]) {