Hello.
In admin/includes/functions/general.php there's a little mistake in create_coupon_code(), it's present at least in version 1.3.7 and 1.3.0.1 (as it's shown in http://phpxref.com/xref/zencart/_fun...n_code.html.gz )
Though it's hard to achieve, the error can lead to an infinite loop in certain cirsumstances: when the coupon_code already exists.
I've attached a TXT with indented code, as long as this forum doesn't allow me preformatted text.
Original code:
////
// Create a Coupon Code. length may be between 1 and 16 Characters
// $salt needs some thought.
function create_coupon_code($salt="secret", $length=SECURITY_CODE_LENGTH) {
global $db;
$ccid = md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
srand((double)microtime()*1000000); // seed the random number generator
$random_start = @rand(0, (128-$length));
$good_result = 0;
while ($good_result == 0) {
$id1=substr($ccid, $random_start,$length);
$query = $db->Execute("select coupon_code
from " . TABLE_COUPONS . "
where coupon_code = '" . $id1 . "'");
if ($query->RecordCount() < 1 ) $good_result = 1;
}
return $id1;
}
Proposed corrected code:
////
// Create a Coupon Code. length may be between 1 and 16 Characters
// $salt needs some thought.
function create_coupon_code($salt="secret", $length=SECURITY_CODE_LENGTH) {
global $db;
$ccid = md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
$ccid .= md5(uniqid("","salt"));
srand((double)microtime()*1000000); // seed the random number generator
$good_result = 0;
while ($good_result == 0) {
$random_start = @rand(0, (128-$length));
$id1=substr($ccid, $random_start,$length);
$query = $db->Execute("select coupon_code
from " . TABLE_COUPONS . "
where coupon_code = '" . $id1 . "'");
if ($query->RecordCount() < 1 ) $good_result = 1;
}
return $id1;
}
Hoping this would be useful,
Juan Pablo Gil,
Working in weekends from Chile.



