Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Add validation on length of record left and right side
Browse files Browse the repository at this point in the history
  • Loading branch information
LordGaav committed Feb 27, 2012
1 parent 53d2803 commit 4149d45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion classes/TemplateFunctions.class.php
Expand Up @@ -193,7 +193,7 @@ public static function create_template($response, $data, &$out = null) {

if ($record->execute() === false) {
$response->code = Response::INTERNALSERVERERROR;
$response->error = sprintf("Rolling back transaction, failed to insert template record - name: '%s', type: '%s', content: '%s', ttl: '%s', prio: '%s'", $r_name, $r_type, $r_content, $r_ttl, $r_prio);
$response->error = sprintf("Rolling back transaction, failed to insert template record - name: '%s', type: '%s', content: '%s', ttl: '%s', prio: '%s', ERROR: %s", $r_name, $r_type, $r_content, $r_ttl, $r_prio, var_export($record->errorInfo(), true));
$response->error_detail = "TEMPLATE_RECORD_INSERT_FAILED";

$connection->rollback();
Expand Down
27 changes: 19 additions & 8 deletions classes/Validators.class.php
Expand Up @@ -319,7 +319,7 @@ public function initialize($data = null) {
"valid_name" => array(
"rule" => array("check_record_name"),
"code" => "RECORD_INVALID_NAME",
"message" => "Record name is not valid. Must start with an alphanumeric character, and may only contain alphanumeric characters and dots (.). Must end in a valid tld. May start with '*.' to indicate a wildcard domain."
"message" => "Record name is not valid. Must start with an alphanumeric character, and may only contain alphanumeric characters and dots (.). Must end in a valid tld. May start with '*.' to indicate a wildcard domain. Subdomains must be 61 characters or less."
)
),
"priority" => array(
Expand Down Expand Up @@ -362,18 +362,22 @@ public function initialize($data = null) {

public function check_record_name($content) {
if ($this->record_type === "TEMPLATE") {
if (preg_match(VALID_TEMPLATE_NAME, $content) === 1) {
return true;
} else {
if (preg_match(VALID_TEMPLATE_NAME, $content) !== 1) {
return "Template record name is not valid. Must start with an alphanumeric character, and may only contain alphanumeric characters and dots (.). Must end in a valid tld or '[ZONE]'. May start with '*.' to indicate a wildcard domain.";
}
if (strlen($content) > 127) {
return "Template record name is too long, must be less than 127 characters.";
}
} else {
if (preg_match(VALID_RECORD_NAME, $content) === 1) {
return true;
} else {
return "Record name is not valid. Must start with an alphanumeric character, and may only contain alphanumeric characters and dots (.). Must end in a valid tld. May start with '*.' to indicate a wildcard domain.";
if (preg_match(VALID_RECORD_NAME, $content) !== 1) {
return "Record name is not valid. Must start with an alphanumeric character, and may only contain alphanumeric characters and dots (.). Must end in a valid tld. May start with '*.' to indicate a wildcard domain. Subdomains must be 61 characters or less.";
}
if (strlen($content) > 253) {
return "Record name is too long, must be less than 253 characters.";
}
}

return true;
}

public function check_record_type($content) {
Expand Down Expand Up @@ -444,6 +448,13 @@ public function check_record_content($content) {
return false;
}

if (strlen($content) > 4096) {
return array(
"message" => $prefix . "Content is too long, must be less than 4096 characters.",
"code" => "RECORD_RHS_TOO_LONG"
);
}

switch ($this->type) {
case "A":
if (preg_match(VALID_IPV4, $content) === 0) {
Expand Down
1 change: 1 addition & 0 deletions codes.txt
Expand Up @@ -42,6 +42,7 @@ RECORD_RHS_SRV_INVALID_PART_x
RECORD_RHS_SRV_PARTS_MISSING
RECORD_RHS_SSHFP_INVALID_PART_x
RECORD_RHS_SSHFP_PARTS_MISSING
RECORD_RHS_TOO_LONG
TEMPLATE_ALREADY_EXISTS
TEMPLATE_DELETE_FAILED
TEMPLATE_DOES_NOT_EXIST
Expand Down

0 comments on commit 4149d45

Please sign in to comment.