103 lines
3.4 KiB
Diff
103 lines
3.4 KiB
Diff
From de767ee03e6c0c4b0d7bb7df4c8c97c656cd955f Mon Sep 17 00:00:00 2001
|
|
From: Jens Osterkamp <jens@linux.vnet.ibm.com>
|
|
Date: Mon, 15 Aug 2011 18:17:05 -0700
|
|
Subject: [PATCH 27/29] prevent crash on invalid response code
|
|
|
|
If an unknown response code was received for a profile, the lookup of the
|
|
error string could cause a crash.
|
|
|
|
Signed-off-by: Jens Osterkamp <jens@linux.vnet.ibm.com>
|
|
Signed-off-by: John Fastabend <john.r.fastabend@intel.com>
|
|
Signed-off-by: Petr Sabata <contyk@redhat.com>
|
|
---
|
|
include/lldp_vdp.h | 2 ++
|
|
lldp_vdp.c | 24 +++++++++++++++++++++++-
|
|
lldp_vdp_cmds.c | 2 +-
|
|
3 files changed, 26 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/include/lldp_vdp.h b/include/lldp_vdp.h
|
|
index 2f6adf8..b9fd37f 100644
|
|
--- a/include/lldp_vdp.h
|
|
+++ b/include/lldp_vdp.h
|
|
@@ -43,6 +43,7 @@
|
|
#define VDP_RESPONSE_VTID_VIOLATION 0x4
|
|
#define VDP_RESPONSE_VTID_VER_VIOLATION 0x5
|
|
#define VDP_RESPONSE_OUT_OF_SYNC 0x6
|
|
+#define VDP_RESPONSE_UNKNOWN 0xfe
|
|
#define VDP_RESPONSE_NO_RESPONSE 0xff
|
|
|
|
extern const char * const vsi_responses[];
|
|
@@ -137,6 +138,7 @@ void vdp_ack_profiles(struct vdp_data *vd, int seqnr);
|
|
int vdp_indicate(struct vdp_data *vd, struct unpacked_tlv *tlv, int ecp_mode);
|
|
int vdp_vsis_pending(struct vdp_data *vd);
|
|
int vdp_vsis(char *ifname);
|
|
+const char *vdp_response2str(int);
|
|
void vdp_print_profile(struct vsi_profile *);
|
|
void ecp_somethingChangedLocal(struct vdp_data *vd, bool flag);
|
|
void ecp_rx_send_ack_frame(struct vdp_data *vd);
|
|
diff --git a/lldp_vdp.c b/lldp_vdp.c
|
|
index 5b8ce46..15fed51 100644
|
|
--- a/lldp_vdp.c
|
|
+++ b/lldp_vdp.c
|
|
@@ -51,6 +51,8 @@ const char * const vsi_responses[] = {
|
|
[VDP_RESPONSE_VTID_VIOLATION] = "VTID violation",
|
|
[VDP_RESPONSE_VTID_VER_VIOLATION] = "VTID version violation",
|
|
[VDP_RESPONSE_OUT_OF_SYNC] = "out of sync",
|
|
+ [VDP_RESPONSE_UNKNOWN] = "unknown response",
|
|
+ [VDP_RESPONSE_NO_RESPONSE] = "no response",
|
|
};
|
|
|
|
const char * const vsi_states[] = {
|
|
@@ -124,6 +126,26 @@ static void vdp_free_data(struct vdp_user_data *ud)
|
|
}
|
|
}
|
|
|
|
+/* vdp_response2str - map response to string
|
|
+ * @response: response received
|
|
+ *
|
|
+ * no return value
|
|
+ *
|
|
+ * maps VDP response received for a profile to human readable string for
|
|
+ * printing.
|
|
+ */
|
|
+const char *vdp_response2str(int response)
|
|
+{
|
|
+ if ((response >= VDP_RESPONSE_SUCCESS) &&
|
|
+ (response <= VDP_RESPONSE_OUT_OF_SYNC))
|
|
+ return vsi_responses[response];
|
|
+
|
|
+ if (response == VDP_RESPONSE_NO_RESPONSE)
|
|
+ return vsi_responses[VDP_RESPONSE_NO_RESPONSE];
|
|
+
|
|
+ return vsi_responses[VDP_RESPONSE_UNKNOWN];
|
|
+}
|
|
+
|
|
/* vdp_print_profile - print a vsi profile
|
|
* @profile: profile to print
|
|
*
|
|
@@ -990,7 +1012,7 @@ int vdp_indicate(struct vdp_data *vd, struct unpacked_tlv *tlv, int ecp_mode)
|
|
LLDPAD_DBG("%s(%i): profile response: %s (%i) "
|
|
"for profile 0x%02x at state %s.\n",
|
|
__func__, __LINE__,
|
|
- vsi_responses[p->response],
|
|
+ vdp_response2str(p->response),
|
|
p->response, p->instance[15],
|
|
vsi_states[p->state]);
|
|
free(profile);
|
|
diff --git a/lldp_vdp_cmds.c b/lldp_vdp_cmds.c
|
|
index 8cc871f..04f6fc1 100644
|
|
--- a/lldp_vdp_cmds.c
|
|
+++ b/lldp_vdp_cmds.c
|
|
@@ -97,7 +97,7 @@ static char * print_profile(char *s, size_t length, struct vsi_profile *p)
|
|
return r;
|
|
|
|
c = snprintf(s, length, "response: %i (%s)\n", p->response,
|
|
- vsi_responses[p->response]);
|
|
+ vdp_response2str(p->response));
|
|
s = check_and_update(&total, &length, s, c);
|
|
if (!s)
|
|
return r;
|
|
--
|
|
1.7.6
|
|
|