Commit 421c4ae9 authored by Max Kellermann's avatar Max Kellermann

protocol/ArgParser: fix integer overflow in parse_range()

Casting std::numeric_limits<unsigned>::max() to "long" leads to an overflow if sizeof(unsigned)==sizeof(long), and the result will be -1. This happens on some 32 bit architectures, for example ARM and WIN32. Workaround: use std::numeric_limits<int>::max(), which is the largest signed integer. Since sizeof(long)>=sizeof(int), this will never overflow. Fixes Mantis ticket 0004080.
parent 4907f610
ver 0.18.14 (not yet released) ver 0.18.14 (not yet released)
* protocol
- fix range parser bug on certain 32 bit architectures
ver 0.18.13 (2014/08/31) ver 0.18.13 (2014/08/31)
* protocol * protocol
......
...@@ -81,7 +81,7 @@ check_range(Client &client, unsigned *value_r1, unsigned *value_r2, ...@@ -81,7 +81,7 @@ check_range(Client &client, unsigned *value_r1, unsigned *value_r2,
/* compatibility with older MPD versions: specifying /* compatibility with older MPD versions: specifying
"-1" makes MPD display the whole list */ "-1" makes MPD display the whole list */
*value_r1 = 0; *value_r1 = 0;
*value_r2 = std::numeric_limits<unsigned>::max(); *value_r2 = std::numeric_limits<int>::max();
return true; return true;
} }
...@@ -108,7 +108,7 @@ check_range(Client &client, unsigned *value_r1, unsigned *value_r2, ...@@ -108,7 +108,7 @@ check_range(Client &client, unsigned *value_r1, unsigned *value_r2,
} }
if (test == test2) if (test == test2)
value = std::numeric_limits<unsigned>::max(); value = std::numeric_limits<int>::max();
if (value < 0) { if (value < 0) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment