Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-15942 - separate data escaped for db insertion from unescaped data

  • Loading branch information...
commit f038db5c7c13a916fbba0ee36529d7b83d444510 1 parent fff59be
peterbulmer authored

Showing 2 changed files with 45 additions and 25 deletions. Show diff stats Hide diff stats

  1. +4 2 admin/mnet/peers.php
  2. +41 23 mnet/peer.php
6 admin/mnet/peers.php
@@ -96,6 +96,7 @@
96 96
97 97 if (isset($form->deleted) && ($form->deleted == '0' || $form->deleted == '1')) {
98 98 $mnet_peer->deleted = $form->deleted;
  99 + $mnet_peer->updateparams->deleted = $form->deleted;
99 100 }
100 101
101 102 if (isset($form->public_key)) {
@@ -106,9 +107,10 @@
106 107 } else {
107 108 $oldkey = $mnet_peer->public_key;
108 109 $mnet_peer->public_key = $form->public_key;
109   - $mnet_peer->public_key_expires = $mnet_peer->check_common_name($form->public_key);
  110 + $mnet_peer->updateparams->public_key = $form->public_key;
  111 + $mnet_peer->public_key_expires = $mnet_peer->check_common_name($form->public_key);
  112 + $mnet_peer->updateparams->public_key_expires = $mnet_peer->check_common_name($form->public_key);
110 113 if ($mnet_peer->public_key_expires == false) {
111   - $mnet_peer->public_key == $oldkey;
112 114 $errmsg = '<br />';
113 115 foreach ($mnet_peer->error as $err) {
114 116 $errmsg .= $err['code'] . ': ' . $err['text'].'<br />';
64 mnet/peer.php
@@ -10,6 +10,8 @@
10 10
11 11 class mnet_peer {
12 12
  13 + //Unless stated otherwise, properties of this object are unescaped, and unsafe to
  14 + //insert into the db without further processing.
13 15 var $id = 0;
14 16 var $wwwroot = '';
15 17 var $ip_address = '';
@@ -20,8 +22,12 @@ class mnet_peer {
20 22 var $last_log_id = 0;
21 23 var $keypair = array();
22 24 var $error = array();
  25 + //Object whose properties need to be put into the database:
  26 + //(properties here are slashescaped)
  27 + var $updateparams;
23 28
24 29 function mnet_peer() {
  30 + $this->updateparams = new stdClass();
25 31 return true;
26 32 }
27 33
@@ -44,7 +50,8 @@ function bootstrap($wwwroot, $pubkey = null) {
44 50 return false;
45 51 }
46 52
47   - $this->name = $wwwroot;
  53 + $this->name = stripslashes($wwwroot);
  54 + $this->updateparams->name = $wwwroot;
48 55
49 56 // TODO: In reality, this will be prohibitively slow... need another
50 57 // default - maybe blank string
@@ -53,24 +60,35 @@ function bootstrap($wwwroot, $pubkey = null) {
53 60 $count = preg_match("@<title>(.*)</title>@siU", $homepage, $matches);
54 61 if ($count > 0) {
55 62 $this->name = $matches[1];
  63 + $this->updateparams->name = addslashes($matches[1]);
56 64 }
57 65 }
58 66
59   - $this->wwwroot = $wwwroot;
60   - $this->ip_address = $ip_address;
61   - $this->deleted = 0;
  67 + $this->wwwroot = stripslashes($wwwroot);
  68 + $this->updateparams->wwwroot = $wwwroot;
  69 + $this->ip_address = $ip_address;
  70 + $this->updateparams->ip_address = $ip_address;
  71 + $this->deleted = 0;
  72 + $this->updateparams->deleted = 0;
62 73 if(empty($pubkey)) {
63   - $this->public_key = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
  74 + $pubkeytemp = clean_param(mnet_get_public_key($this->wwwroot), PARAM_PEM);
64 75 } else {
65   - $this->public_key = clean_param($pubkey, PARAM_PEM);
  76 + $pubkeytemp = clean_param($pubkey, PARAM_PEM);
66 77 }
67   - $this->public_key_expires = $this->check_common_name($this->public_key);
68   - $this->last_connect_time = 0;
69   - $this->last_log_id = 0;
  78 + $this->public_key_expires = $this->check_common_name($pubkeytemp);
  79 +
70 80 if ($this->public_key_expires == false) {
71   - $this->public_key == '';
72 81 return false;
73 82 }
  83 + $this->updateparams->public_key_expires = $this->public_key_expires;
  84 +
  85 + $this->updateparams->public_key = $pubkeytemp;
  86 + $this->public_key = $pubkeytemp;
  87 +
  88 + $this->last_connect_time = 0;
  89 + $this->updateparams->last_connect_time = 0;
  90 + $this->last_log_id = 0;
  91 + $this->updateparams->last_log_id = 0;
74 92 }
75 93
76 94 return true;
@@ -82,11 +100,13 @@ function delete() {
82 100 $users = count_records('user','mnethostid', $this->id);
83 101 if ($users > 0) {
84 102 $this->deleted = 1;
  103 + $this->updateparams->deleted = 1;
85 104 }
86 105
87 106 $actions = count_records('mnet_log','hostid', $this->id);
88 107 if ($actions > 0) {
89 108 $this->deleted = 1;
  109 + $this->updateparams->deleted = 1;
90 110 }
91 111
92 112 $obj = delete_records('mnet_rpc2host', 'host_id', $this->id);
@@ -145,34 +165,32 @@ function check_common_name($key) {
145 165 }
146 166
147 167 function commit() {
148   - $obj = new stdClass();
149   -
150   - $obj->wwwroot = $this->wwwroot;
151   - $obj->ip_address = $this->ip_address;
152   - $obj->name = $this->name;
153   - $obj->public_key = $this->public_key;
154   - $obj->public_key_expires = $this->public_key_expires;
155   - $obj->deleted = $this->deleted;
156   - $obj->last_connect_time = $this->last_connect_time;
157   - $obj->last_log_id = $this->last_log_id;
  168 + $obj = $this->updateparams;
158 169
159 170 if (isset($this->id) && $this->id > 0) {
160 171 $obj->id = $this->id;
161   - return update_record('mnet_host', $obj);
  172 + $dbresult = update_record('mnet_host', $obj);
162 173 } else {
163 174 $this->id = insert_record('mnet_host', $obj);
164   - return $this->id > 0;
  175 + $dbresult = ($this->id > 0);
  176 + }
  177 + //If the insert/update was successful, clear the parameters that need updating
  178 + if ($dbresult) {
  179 + $this->updateparams = new stdClass();
165 180 }
  181 + return $dbresult;
166 182 }
167 183
168 184 function touch() {
169 185 $this->last_connect_time = time();
  186 + $this->updateparams->last_connect_time = time();
170 187 $this->commit();
171 188 }
172 189
173 190 function set_name($newname) {
174 191 if (is_string($newname) && strlen($newname <= 80)) {
175   - $this->name = $newname;
  192 + $this->name = stripslashes($newname);
  193 + $this->updateparams->name = $newname;
176 194 return true;
177 195 }
178 196 return false;

0 comments on commit f038db5

Please sign in to comment.
Something went wrong with that request. Please try again.