antirez / disque

Disque is a distributed message broker
BSD 3-Clause "New" or "Revised" License
8.01k stars 537 forks source link

ADDJOB MAXLEN Off-by-One Error #109

Closed felixbuenemann closed 9 years ago

felixbuenemann commented 9 years ago

If I try to enqueue a job with MAXLEN 1, queueing fails for the third instead of the second job.

This seems to be due to an off by one error in job.c where the length is compared with > instead of >=.

Example:

127.0.0.1:7711> ADDJOB foo bar 1000 MAXLEN 1
DI1dcc90feebc8085a2e65bc0d41c1d49b46cf357c05a0SQ
127.0.0.1:7711> ADDJOB foo bar 1000 MAXLEN 1
DI1dcc90fe8de6220e6339debc3b3a9ff630b4aa7805a0SQ
127.0.0.1:7711> ADDJOB foo bar 1000 MAXLEN 1
(error) MAXLEN Queue is already longer than the specified MAXLEN count
127.0.0.1:7711>

Expected the failure on the second ADDJOB invocation instead of on the third.

sunheehnus commented 9 years ago

LGTM

antirez commented 9 years ago

Thank you @felixbuenemann and @sunheehnus, I merged the PR fixing this.