Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1722)

Unified Diff: runtime/platform/json.cc

Issue 12035086: Verify integrity of JSOM messages sent to debugger client (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/platform/json.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/json.cc
===================================================================
--- runtime/platform/json.cc (revision 17486)
+++ runtime/platform/json.cc (working copy)
@@ -202,6 +202,7 @@
Set(json_object);
}
+
void JSONReader::Set(const char* json_object) {
scanner_.SetText(json_object);
json_object_ = json_object;
@@ -209,6 +210,93 @@
}
+bool JSONReader::CheckMessage() {
+ scanner_.SetText(json_object_);
+ scanner_.Scan();
+ CheckObject();
+ return true;
+}
+
+
+void JSONReader::CheckValue() {
+ switch (scanner_.CurrentToken()) {
+ case JSONScanner::TokenLBrace:
+ CheckObject();
+ break;
+ case JSONScanner::TokenLBrack:
+ CheckArray();
+ break;
+ case JSONScanner::TokenString: {
+ // Check the encoding.
+ const char* s = ValueChars();
+ int remaining = ValueLen();
+ while (remaining > 0) {
+ if ((*s == '\n') || (*s == '\t')) {
+ OS::Print("Un-escaped character in JSON string: '%s'\n",
+ ValueChars());
+ ASSERT(!"illegal character in JSON string value");
Tom Ball 2013/01/24 23:28:23 Assert when checking caller data? Seems an excepti
hausner 2013/01/24 23:35:15 We don't use exceptions in our C++ code. Asserting
+ }
+ s++;
+ remaining--;
+ }
+ scanner_.Scan();
+ break;
+ }
+ case JSONScanner::TokenInteger:
+ case JSONScanner::TokenTrue:
+ case JSONScanner::TokenFalse:
+ case JSONScanner::TokenNull:
+ scanner_.Scan();
+ break;
+ default:
+ OS::Print("Malformed JSON: expected a value but got '%s'\n",
+ scanner_.TokenChars());
+ ASSERT(!"illegal JSON value found");
+ }
+}
+
+#define CHECK_TOKEN(token) \
+ if (scanner_.CurrentToken() != token) { \
+ OS::Print("Malformed JSON: expected %s but got '%s'\n", \
+ #token, scanner_.TokenChars()); \
+ } \
+ ASSERT(scanner_.CurrentToken() == token);
+
+void JSONReader::CheckArray() {
+ CHECK_TOKEN(JSONScanner::TokenLBrack);
+ scanner_.Scan();
+ while (scanner_.CurrentToken() != JSONScanner::TokenRBrack) {
+ CheckValue();
+ if (scanner_.CurrentToken() != JSONScanner::TokenComma) {
+ break;
+ }
+ scanner_.Scan();
+ }
+ CHECK_TOKEN(JSONScanner::TokenRBrack);
+ scanner_.Scan();
+}
+
+
+void JSONReader::CheckObject() {
+ CHECK_TOKEN(JSONScanner::TokenLBrace);
+ scanner_.Scan();
+ while (scanner_.CurrentToken() == JSONScanner::TokenString) {
+ scanner_.Scan();
+ CHECK_TOKEN(JSONScanner::TokenColon);
+ scanner_.Scan();
+ CheckValue();
+ if (scanner_.CurrentToken() != JSONScanner::TokenComma) {
+ break;
+ }
+ scanner_.Scan();
+ }
+ CHECK_TOKEN(JSONScanner::TokenRBrace);
+ scanner_.Scan();
+}
+
+#undef CHECK_TOKEN
+
+
bool JSONReader::Seek(const char* name) {
error_ = false;
scanner_.SetText(json_object_);
« no previous file with comments | « runtime/platform/json.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698