mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-17 11:00:59 -05:00
Fix handling of max_data_size == 0.
When I reworked the support for rekeying after a certain amount of data had been sent, I forgot the part where configuring the max data limit to zero means 'never rekey due to data transfer volume'. So I was incautiously checking the 'running' flag in the new DataTransferStats to find out whether we needed to rekey, forgetting that sometimes running=false means the transfer limit has expired, and sometimes it means there never was one in the first place. To fix this, I've got rid of the boolean return value from DTS_CONSUME and turned it into an 'expired' flag in DataTransferStats, separate from the 'running' flag. Now everything consistently checks 'expired' to find out whether to rekey, and there's a new reset function that reliably clears 'expired' but sets 'running' depending on whether the size is nonzero. (Also, while I'm at it, I've turned the DTS_CONSUME macro into an inline function, because that's becoming my general preference now that C99 is allowed in this code base.)
This commit is contained in:
48
sshbpp.h
48
sshbpp.h
@ -80,25 +80,47 @@ bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin);
|
||||
* purposes of triggering an SSH-2 rekey when either one gets over a
|
||||
* configured limit. In each direction, the flag 'running' indicates
|
||||
* that we haven't hit the limit yet, and 'remaining' tracks how much
|
||||
* longer until we do. The macro DTS_CONSUME subtracts a given amount
|
||||
* from the counter in a particular direction, and evaluates to a
|
||||
* boolean indicating whether the limit has been hit.
|
||||
* longer until we do. The function dts_consume() subtracts a given
|
||||
* amount from the counter in a particular direction, and sets
|
||||
* 'expired' if the limit has been hit.
|
||||
*
|
||||
* The limit is sticky: once 'running' has flipped to false,
|
||||
* 'remaining' is no longer decremented, so it shouldn't dangerously
|
||||
* wrap round.
|
||||
*/
|
||||
struct DataTransferStats {
|
||||
struct {
|
||||
bool running;
|
||||
unsigned long remaining;
|
||||
} in, out;
|
||||
struct DataTransferStatsDirection {
|
||||
bool running, expired;
|
||||
unsigned long remaining;
|
||||
};
|
||||
#define DTS_CONSUME(stats, direction, size) \
|
||||
((stats)->direction.running && \
|
||||
(stats)->direction.remaining <= (size) ? \
|
||||
((stats)->direction.running = false, true) : \
|
||||
((stats)->direction.remaining -= (size), false))
|
||||
struct DataTransferStats {
|
||||
struct DataTransferStatsDirection in, out;
|
||||
};
|
||||
static inline void dts_consume(struct DataTransferStatsDirection *s,
|
||||
unsigned long size_consumed)
|
||||
{
|
||||
if (s->running) {
|
||||
if (s->remaining <= size_consumed) {
|
||||
s->running = false;
|
||||
s->expired = true;
|
||||
} else {
|
||||
s->remaining -= size_consumed;
|
||||
}
|
||||
}
|
||||
}
|
||||
static inline void dts_reset(struct DataTransferStatsDirection *s,
|
||||
unsigned long starting_size)
|
||||
{
|
||||
s->expired = false;
|
||||
s->remaining = starting_size;
|
||||
/*
|
||||
* The semantics of setting CONF_ssh_rekey_data to zero are to
|
||||
* disable data-volume based rekeying completely. So if the
|
||||
* starting size is actually zero, we don't set 'running' to true
|
||||
* in the first place, which means we won't ever set the expired
|
||||
* flag.
|
||||
*/
|
||||
s->running = (starting_size != 0);
|
||||
}
|
||||
|
||||
BinaryPacketProtocol *ssh2_bpp_new(
|
||||
LogContext *logctx, struct DataTransferStats *stats, bool is_server);
|
||||
|
Reference in New Issue
Block a user