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

Side by Side Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 180743020: guard against invalid request id / method (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library protocol; 5 library protocol;
6 6
7 import 'dart:convert' show JsonDecoder; 7 import 'dart:convert' show JsonDecoder;
8 8
9 /** 9 /**
10 * Instances of the class [Request] represent a request that was received. 10 * Instances of the class [Request] represent a request that was received.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 * 66 *
67 * where the parameters are optional and can contain any number of name/value 67 * where the parameters are optional and can contain any number of name/value
68 * pairs. 68 * pairs.
69 */ 69 */
70 factory Request.fromString(String data) { 70 factory Request.fromString(String data) {
71 try { 71 try {
72 var result = DECODER.convert(data); 72 var result = DECODER.convert(data);
73 if (result is! Map) { 73 if (result is! Map) {
74 return null; 74 return null;
75 } 75 }
76 String id = result[Request.ID]; 76 var id = result[Request.ID];
77 String method = result[Request.METHOD]; 77 var method = result[Request.METHOD];
78 if (id is! String || method is! String) {
79 return null;
80 }
78 var params = result[Request.PARAMS]; 81 var params = result[Request.PARAMS];
79 Request request = new Request(id, method); 82 Request request = new Request(id, method);
80 if (params is Map) { 83 if (params is Map) {
Brian Wilkerson 2014/03/05 16:15:16 So it looks like we're returning null if the forma
danrubel 2014/03/05 18:39:07 Good point. Done.
81 params.forEach((String key, Object value) { 84 params.forEach((String key, Object value) {
Brian Wilkerson 2014/03/05 16:15:16 Should we test that the key is always a String?
danrubel 2014/03/05 18:39:07 I don't think we want to restrict the value of a p
82 request.setParameter(key, value); 85 request.setParameter(key, value);
83 }); 86 });
84 } 87 }
85 return request; 88 return request;
86 } catch (exception) { 89 } catch (exception) {
87 return null; 90 return null;
88 } 91 }
89 } 92 }
90 93
91 /** 94 /**
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 /** 577 /**
575 * The response to be returned as a result of the failure. 578 * The response to be returned as a result of the failure.
576 */ 579 */
577 final Response response; 580 final Response response;
578 581
579 /** 582 /**
580 * Initialize a newly created exception to return the given reponse. 583 * Initialize a newly created exception to return the given reponse.
581 */ 584 */
582 RequestFailure(this.response); 585 RequestFailure(this.response);
583 } 586 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/protocol_test.dart » ('j') | pkg/analysis_server/test/protocol_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698