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

Side by Side Diff: remoting/webapp/host_controller.js

Issue 10221021: Protect all uses of JSON.parse against exceptions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. Created 8 years, 7 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
« no previous file with comments | « remoting/webapp/client_screen.js ('k') | remoting/webapp/host_list.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** @constructor */ 10 /** @constructor */
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 }; 237 };
238 238
239 /** 239 /**
240 * Parse a stringified host configuration and return it as a dictionary if it 240 * Parse a stringified host configuration and return it as a dictionary if it
241 * is well-formed and contains both host_id and xmpp_login keys. null is 241 * is well-formed and contains both host_id and xmpp_login keys. null is
242 * returned if either key is missing, or if the configuration is corrupt. 242 * returned if either key is missing, or if the configuration is corrupt.
243 * @param {string} configStr The host configuration, JSON encoded to a string. 243 * @param {string} configStr The host configuration, JSON encoded to a string.
244 * @return {Object.<string,string>|null} The host configuration. 244 * @return {Object.<string,string>|null} The host configuration.
245 */ 245 */
246 function parseHostConfig_(configStr) { 246 function parseHostConfig_(configStr) {
247 try { 247 var config = /** @type {Object.<string,string>} */ jsonParseSafe(configStr);
248 var config = /** @type {Object.<string,string>} */ JSON.parse(configStr); 248 if (config &&
249 if (typeof config['host_id'] == 'string' && 249 typeof config['host_id'] == 'string' &&
250 typeof config['xmpp_login'] == 'string') { 250 typeof config['xmpp_login'] == 'string') {
251 return config; 251 return config;
252 } 252 } else {
253 } catch (err) { 253 console.error('Invalid getDaemonConfig response.');
254 } 254 }
255 return null; 255 return null;
256 } 256 }
257 257
258 /** 258 /**
259 * @param {string} newPin The new PIN to set 259 * @param {string} newPin The new PIN to set
260 * @param {function(remoting.HostController.AsyncResult):void} callback 260 * @param {function(remoting.HostController.AsyncResult):void} callback
261 * Callback to be called when finished. 261 * Callback to be called when finished.
262 * @return {void} Nothing. 262 * @return {void} Nothing.
263 */ 263 */
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 try { 348 try {
349 this.plugin_.getDaemonConfig(onConfig); 349 this.plugin_.getDaemonConfig(onConfig);
350 } catch (err) { 350 } catch (err) {
351 this.setHost(null); 351 this.setHost(null);
352 onDone(); 352 onDone();
353 } 353 }
354 }; 354 };
355 355
356 /** @type {remoting.HostController} */ 356 /** @type {remoting.HostController} */
357 remoting.hostController = null; 357 remoting.hostController = null;
OLDNEW
« no previous file with comments | « remoting/webapp/client_screen.js ('k') | remoting/webapp/host_list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698