Hi.

I was running OpenIPMI against not-properly-behaving BMC, and discovered a 
problem in incoming packet sequence number checking.

Attached patch should fix it.

Nikita
From 504bb320e1cb621c013560c0ea9878e803166b7d Mon Sep 17 00:00:00 2001
From: Nikita Yushchenko <[email protected]>
Date: Thu, 13 Jun 2013 11:58:23 +0400
Subject: [PATCH] Fix incoming packet sequence number checking

This fixes misbehaviour of code in check_session_seq_num() when
incoming sequrnce number contains garbage.

Also, it fixes type of 'bit' variable same as type of (*map)
it operates on... but still not enough for lt_allowed=16.

Signed-off-by: Nikita Yushchenko <[email protected]>
---
 lib/ipmi_lan.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/ipmi_lan.c b/lib/ipmi_lan.c
index c55445e..c138b9e 100644
--- a/lib/ipmi_lan.c
+++ b/lib/ipmi_lan.c
@@ -2854,15 +2854,15 @@ check_session_seq_num(lan_data_t *lan, uint32_t seq,
 		      int gt_allowed, int lt_allowed)
 {
     /* Check the sequence number. */
-    if ((int) (seq - *in_seq) <= gt_allowed) {
-	/* It's after the current sequence number, but within 8.  We
-           move the sequence number forward. */
+    if ((int) (seq - *in_seq) >= 0 && (int) (seq - *in_seq) <= gt_allowed) {
+	/* It's after the current sequence number, but within gt_allowed.
+	   We move the sequence number forward. */
 	*map <<= seq - *in_seq;
 	*map |= 1;
 	*in_seq = seq;
-    } else if ((int) (*in_seq - seq) <= lt_allowed) {
-	/* It's before the current sequence number, but within 8. */
-	uint8_t bit = 1 << (*in_seq - seq);
+    } else if ((int) (*in_seq - seq) >= 0 && (int) (*in_seq - seq) <= lt_allowed) {
+	/* It's before the current sequence number, but within lt_allowed. */
+	uint16_t bit = 1 << (*in_seq - seq);
 	if (*map & bit) {
 	    /* We've already received the message, so discard it. */
 	    add_stat(lan->ipmi, STAT_DUPLICATES, 1);
-- 
1.7.2.5

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Openipmi-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openipmi-developer

Reply via email to