From 82dc0b33b9af5094d78f3ecd855900e49c580343 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 27 Jun 2012 15:33:43 +0200 Subject: [PATCH] s3:smb2_server: make sure sequence numbers don't wrap at UINT64_MAX metze --- source3/smbd/smb2_server.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index 320923a4cfe..b01d01f8d59 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -570,11 +570,26 @@ static void smb2_set_operation_credit(struct smbd_server_connection *sconn, } /* - * remove the range we'll already granted to the client + * sequence numbers should not wrap + * + * 1. calculate the possible credits until + * the sequence numbers start to wrap on 64-bit. + * + * 2. UINT64_MAX is used for Break Notifications. + * + * 2. truncate the possible credits to the maximum + * credits we want to grant to the client in total. + * + * 3. remove the range we'll already granted to the client * this makes sure the client consumes the lowest sequence * number, before we can grant additional credits. */ - credits_possible = sconn->smb2.max_credits; + credits_possible = UINT64_MAX - sconn->smb2.seqnum_low; + if (credits_possible > 0) { + /* remove UINT64_MAX */ + credits_possible -= 1; + } + credits_possible = MIN(credits_possible, sconn->smb2.max_credits); credits_possible -= sconn->smb2.seqnum_range; credits_granted = MIN(credits_granted, credits_possible); -- 2.11.4.GIT