瀏覽代碼

2009-05-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Avoid std::bad_alloc for negative bencode string length.
	* src/bencode.cc
Tatsuhiro Tsujikawa 16 年之前
父節點
當前提交
47b08786eb
共有 2 個文件被更改,包括 7 次插入2 次删除
  1. 5 0
      ChangeLog
  2. 2 2
      src/bencode.cc

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+2009-05-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Avoid std::bad_alloc for negative bencode string length.
+	* src/bencode.cc
+	
 2009-05-06  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Supported segmented downloading with chunked transfer encoding and

+ 2 - 2
src/bencode.cc

@@ -57,9 +57,9 @@ static void checkdelim(std::istream& ss, const char delim = ':')
 
 static std::string decoderawstring(std::istream& ss)
 {
-  size_t length;
+  int length;
   ss >> length;
-  if(!ss) {
+  if(!ss || length < 0) {
     throw RecoverableException("A positive integer expected but none found.");
   }
   // TODO check length, it must be less than or equal to INT_MAX