<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -254,6 +254,45 @@ void PsiMain::bail()
 
 int main(int argc, char *argv[])
 {
+	// If Psi runs as uri handler the commandline might contain
+	// almost arbitary network supplied data after the &quot;--uri&quot; argument.
+	// To prevent any potentially dangerous options in Psi or
+	// Qt to be triggered by this, filter out the uri and any following data
+	// as early as possible.
+	// see http://www.mozilla.org/security/announce/2007/mfsa2007-23.html
+	// for how this problem affected firefox on windows.
+
+	QString uri;
+	for (int i=1; i&lt;argc; i++) {
+		QString str = QString::fromLocal8Bit(argv[i]);
+		QString var, val;
+		int x = str.find('=');
+		if(x == -1) {
+			var = str;
+			val = &quot;&quot;;
+		} else {
+			var = str.mid(0,x);
+			val = str.mid(x+1);
+		}
+
+		if (var == &quot;--uri&quot;) {
+			uri = val;
+#ifdef Q_WS_WIN
+			// FIXME think about handling of quirks on the windows platform.
+#endif
+			if (uri.isEmpty() &amp;&amp; i+1 &lt; argc) {
+				uri = QString::fromLocal8Bit(argv[i+1]);
+			}
+			
+			// terminate args here. Everything that follow mustn't be availible
+			// in later commandline scanning.
+			argc = i;
+			argv[i] = 0;
+			break;
+		}
+		
+	}
+
 	// NOTE: Qt 4.5 compatibility note: please don't move this call.
 	//   instead, upgrade to QCA 2.0.2, which fixes the bug in the right
 	//   place.
@@ -301,7 +340,6 @@ int main(int argc, char *argv[])
 
 	//dtcp_port = 8000;
 
-	QString uri;
 	for(int n = 1; n &lt; argc; ++n) {
 		QString str = argv[n];
 		QString var, val;
@@ -315,11 +353,6 @@ int main(int argc, char *argv[])
 			val = str.mid(x+1);
 		}
 
-		if (str.startsWith(&quot;xmpp:&quot;)) {
-			uri = str;
-		} else if (var == &quot;--uri&quot;) {
-			uri = val;
-		}
 		//if(var == &quot;--no-gpg&quot;)
 		//	use_gpg = false;
 		//else if(var == &quot;--no-gpg-agent&quot;)</diff>
      <filename>src/main.cpp</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cdbaf47d288562546c25c02b29da8717db5aa103</id>
    </parent>
  </parents>
  <author>
    <name>Martin H</name>
    <email>textshell-I1QKlO@neutronstar.dyndns.org</email>
  </author>
  <url>http://github.com/psi-im/psi/commit/c78a7ddd92af392d326050e2aee2b98b2c12ac50</url>
  <id>c78a7ddd92af392d326050e2aee2b98b2c12ac50</id>
  <committed-date>2009-07-04T15:33:44-07:00</committed-date>
  <authored-date>2009-04-06T09:19:49-07:00</authored-date>
  <message>main.cpp: --uri is now mandatory for xmpp uri opening. Enforce --uri to be the last parameter used.</message>
  <tree>6a13c4ab3865b0994fe160319bb713d423d59c1a</tree>
  <committer>
    <name>Martin H</name>
    <email>textshell-I1QKlO@neutronstar.dyndns.org</email>
  </committer>
</commit>
