From 741293118396823c306daf057ec1c464dd2883d6 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 26 Dec 2009 10:54:00 +0000 Subject: [PATCH] fixed some error handling in lazy_bdecode to handle out-of-memory errors --- ChangeLog | 1 + src/lazy_bdecode.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12ef9cec3..ccc41d593 100644 --- a/ChangeLog +++ b/ChangeLog @@ -96,6 +96,7 @@ release 0.14.8 * force_recheck() no longer crashes on torrents with no metadata * fixed broadcast socket regression from 0.14.7 * fixed hang in NATPMP when shut down while waiting for a response + * fixed some more error handling in bdecode release 0.14.7 diff --git a/src/lazy_bdecode.cpp b/src/lazy_bdecode.cpp index 63ebd0ea7..1b5f8952c 100644 --- a/src/lazy_bdecode.cpp +++ b/src/lazy_bdecode.cpp @@ -47,10 +47,10 @@ namespace namespace libtorrent { - int fail_bdecode(lazy_entry& ret) + int fail_bdecode(lazy_entry& ret, int return_value = -1) { ret.clear(); - return -1; + return return_value; } // fills in 'val' with what the string between start and the @@ -110,10 +110,11 @@ namespace libtorrent start = parse_int(start, end, ':', len); if (start == 0 || start + len + 3 > end || *start != ':') return fail_bdecode(ret); ++start; - if (start == end) fail_bdecode(ret); + if (start == end) return fail_bdecode(ret); lazy_entry* ent = top->dict_append(start); + if (ent == 0) return fail_bdecode(ret, -2); start += len; - if (start >= end) fail_bdecode(ret); + if (start >= end) return fail_bdecode(ret); stack.push_back(ent); t = *start; ++start; @@ -128,6 +129,7 @@ namespace libtorrent continue; } lazy_entry* ent = top->list_append(); + if (ent == 0) return fail_bdecode(ret, -2); stack.push_back(ent); break; }