[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1856: Escape '"' and '\' characters when using a password to authe (in trunk: . src/control src/util)
Author: edmanm
Date: 2007-08-22 21:58:58 -0400 (Wed, 22 Aug 2007)
New Revision: 1856
Modified:
trunk/
trunk/src/control/torcontrol.cpp
trunk/src/util/string.cpp
trunk/src/util/string.h
Log:
r2034@adrastea: edmanm | 2007-08-22 21:58:49 -0400
Escape '"' and '\' characters when using a password to authenticate to Tor.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r2034] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp 2007-08-23 01:22:55 UTC (rev 1855)
+++ trunk/src/control/torcontrol.cpp 2007-08-23 01:58:58 UTC (rev 1856)
@@ -338,7 +338,8 @@
bool
TorControl::authenticate(const QString password, QString *errmsg)
{
- ControlCommand cmd("AUTHENTICATE", QString("\"%1\"").arg(password));
+ ControlCommand cmd("AUTHENTICATE", QString("%1")
+ .arg(string_escape(password)));
ControlReply reply;
QString str;
Modified: trunk/src/util/string.cpp
===================================================================
--- trunk/src/util/string.cpp 2007-08-23 01:22:55 UTC (rev 1855)
+++ trunk/src/util/string.cpp 2007-08-23 01:58:58 UTC (rev 1856)
@@ -130,6 +130,22 @@
return hex;
}
+/** Given a string <b>str</b>, this function returns a quoted string with all
+ * '"' and '\' characters escaped with a single '\'. */
+QString
+string_escape(const QString str)
+{
+ QString out;
+ out.append('\"');
+ for (int i = 0; i < str.length(); i++) {
+ if (str[i] == '\"' || str[i] == '\\')
+ out.append('\\');
+ out.append(str[i]);
+ }
+ out.append('\"');
+ return out;
+}
+
/** Given a quoted string <b>str</b>, this function returns an unquoted,
* unescaped string. <b>str</b> must start and end with an unescaped quote. */
QString
Modified: trunk/src/util/string.h
===================================================================
--- trunk/src/util/string.h 2007-08-23 01:22:55 UTC (rev 1855)
+++ trunk/src/util/string.h 2007-08-23 01:58:58 UTC (rev 1856)
@@ -57,6 +57,10 @@
* util.c. See LICENSE for details on Tor's license. */
QString base16_encode(const QByteArray buf);
+/** Given a string <b>str</b>, this function returns a quoted string with all
+ * '"' and '\' characters escaped with a single '\'. */
+QString string_escape(const QString str);
+
/** Given a quoted string <b>str</b>, this function returns an unquoted,
* unescaped string. <b>str</b> must start and end with an unescaped quote. */
QString string_unescape(const QString str, bool *ok = 0);