PluginProbe
Welcart e-Commerce / 2.12.4
Welcart e-Commerce v2.12.4
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
← All changes | classes/cart.class.php +37 -9 2.11.322.12.4 View file →
@@ -142,8 +142,18 @@
142 142
143 143 if ( $serial_option ) {
144 144 $this->up_serialize( $index, $post_id, $sku );
145 145 } else {
146 + if ( ! isset( $keys[ $index ] ) ) {
147 + /*
148 + * The cart in the session has fewer rows than the posted data
149 + * ( session GC, deletion in another tab, etc. ).
150 + * Skip it, because a null key is converted to "" and would
151 + * write a broken row into the session.
152 + */
153 + $index++;
154 + continue;
155 + }
146 156 $this->serial = $keys[ $index ];
147 157 }
148 158
149 159 if ( ! WCUtils::is_blank( $_POST['quant'][ $index ][ $post_id ][ $sku ] ) ) {
@@ -279,9 +289,15 @@
279 289 $rows = array();
280 290
281 291 $i = 0;
282 292 foreach ( (array) $_SESSION['usces_cart'] as $serial => $qua ) {
283 - $rows[ $i ] = $this->key_unserialize( $serial );
293 + $row = $this->key_unserialize( $serial );
294 + if ( false === $row ) {
295 + /* A row that cannot be restored is unusable for display and ordering, so remove it from the session. */
296 + unset( $_SESSION['usces_cart'][ $serial ] );
297 + continue;
298 + }
299 + $rows[ $i ] = $row;
284 300 $i++;
285 301 }
286 302
287 303 return $rows;
@@ -317,12 +333,13 @@
317 333 $option = $option_field[ urldecode( $key ) ];
318 334 if ( 3 === (int) $option['means'] || 4 === (int) $option['means'] ) {
319 335 if ( is_array( $value ) ) {
320 336 foreach ( $value as $k => $v ) {
321 - $pots[ $key ][ trim( $v ) ] = trim( $v );
337 + $v = trim( wel_safe_text_serialize( $v ) );
338 + $pots[ $key ][ $v ] = $v;
322 339 }
323 340 } else {
324 - $pots[ $key ] = $value;
341 + $pots[ $key ] = wel_safe_text_serialize( $value );
325 342 }
326 343 } else {
327 344 if ( is_array( $value ) ) {
328 345 foreach ( $value as $k => $v ) {
@@ -363,12 +380,13 @@
363 380 if ( isset( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) && is_array( $_POST['itemOption'][ $index ][ $id ][ $sku ] ) ) {
364 381 foreach ( $_POST['itemOption'][ $index ][ $id ][ $sku ] as $key => $value ) {
365 382 if ( is_array( $value ) ) {
366 383 foreach ( $value as $k => $v ) {
384 + $v = wel_safe_text_serialize( $v );
367 385 $pots[ $key ][ $v ] = $v;
368 386 }
369 387 } else {
370 - $pots[ $key ] = $value;
388 + $pots[ $key ] = wel_safe_text_serialize( $value );
371 389 }
372 390 }
373 391 ksort( $pots );
374 392 $sels[ $id ][ $sku ] = $pots;
@@ -382,14 +400,20 @@
382 400 /**
383 401 * Serial key decompression
384 402 *
385 403 * @param string $serial Serial key.
386 - * @return array
404 + * @return array|false False if the serial key cannot be restored ( unserialize failure or invalid format ).
387 405 */
388 406 public function key_unserialize( $serial ) {
389 - $array = @unserialize( $serial );
390 - $ids = array_keys( $array );
391 - $skus = array_keys( $array[ $ids[0] ] );
407 + $array = wel_safe_unserialize( $serial );
408 + if ( ! is_array( $array ) || empty( $array ) ) {
409 + return false;
410 + }
411 + $ids = array_keys( $array );
412 + if ( ! is_array( $array[ $ids[0] ] ) || empty( $array[ $ids[0] ] ) ) {
413 + return false;
414 + }
415 + $skus = array_keys( $array[ $ids[0] ] );
392 416
393 417 $row['serial'] = $serial;
394 418 $row['post_id'] = $ids[0];
395 419 $row['sku'] = $skus[0];
@@ -543,14 +567,18 @@
543 567 }
544 568
545 569 if ( isset( $_POST['reserve'] ) ) {
546 570 foreach ( $_POST['reserve'] as $key => $value ) {
547 - $_SESSION['usces_entry']['reserve'][ $key ] = trim( $value );
571 + $_SESSION['usces_entry']['reserve'][ $key ] = trim( wel_safe_text_serialize( $value ) );
548 572 }
549 573 }
550 574 if ( isset( $_POST['custom_order'] ) ) {
551 575 unset( $_SESSION['usces_entry']['custom_order'] );
576 + $csod_meta = usces_has_custom_field_meta( 'order' );
552 577 foreach ( $_POST['custom_order'] as $key => $value ) {
578 + if ( ! is_array( $csod_meta ) || ! isset( $csod_meta[ $key ] ) ) {
579 + continue;
580 + }
553 581 $value = wel_safe_text_serialize( $value );
554 582 if ( is_array( $value ) ) {
555 583 foreach ( $value as $k => $v ) {
556 584 $_SESSION['usces_entry']['custom_order'][ $key ][ trim( $v ) ] = trim( $v );