← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3019: Fix a crash when parsing messages with Magnet links

 

------------------------------------------------------------
revno: 3019
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2012-08-02 19:11:14 +0200
message:
  Fix a crash when parsing messages with Magnet links
modified:
  changelog.txt
  dcpp/ChatMessage.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2012-08-02 00:34:10 +0000
+++ changelog.txt	2012-08-02 17:11:14 +0000
@@ -32,6 +32,7 @@
 * Fix partial list browsing after loading an old full list (poy)
 * Add QP support (iceman50)
 * [L#305811] Grant extra slot hangs connection in ADC hubs (iceman50)
+* [L#1032227] Fix a crash when parsing messages with Magnet links (poy)
 
 -- 0.799 2012-05-05 --
 * Add icons (iceman50)

=== modified file 'dcpp/ChatMessage.cpp'
--- dcpp/ChatMessage.cpp	2012-07-01 18:41:13 +0000
+++ dcpp/ChatMessage.cpp	2012-08-02 17:11:14 +0000
@@ -130,7 +130,7 @@
 
 	i = 0;
 	size_t begin, end;
-	const auto n = tmp.size();
+	auto n = tmp.size();
 	while((i = tmp.find(':', i)) != string::npos) {
 
 		if((begin = tmp.find_last_of(delimiters, i)) == string::npos) begin = 0; else ++begin;
@@ -151,7 +151,11 @@
 					// magnet link: replace with the friendly name
 					name += " (magnet)";
 					tmp.replace(begin, end - begin, name);
-					end += name.size() - link.size();
+
+					// the size of the string has changed; update counts.
+					auto delta = name.size() - link.size();
+					end += delta;
+					n += delta;
 				}
 
 				addLinkStr(begin, end, link);
@@ -174,6 +178,7 @@
 			if(i + 5 <= end) {
 				addLink(i, end);
 				i = end;
+				continue;
 			}
 		}
 		i += 5;