TT#13256 Validate length of preference values

Don't spill DB error back to panel and API if values > 128 chars.

Change-Id: I8eba737d46be7318e14c6008d889b2545caaeadd
changes/39/12139/2
Andreas Granig 9 years ago
parent bc9a1956b7
commit 77fb204437

@ -59,6 +59,7 @@ has_field 'display_name' => (
},
required => 0,
label => 'Display Name',
maxlength => 128,
);
has_field 'email' => (

@ -110,6 +110,7 @@ sub field_list {
$field = {
name => $meta->attribute,
type => 'Text',
maxlength => 128,
};
} else {
# is only used to add a new field
@ -118,6 +119,7 @@ sub field_list {
type => 'Text',
do_label => 0,
do_wrapper => 1,
maxlength => 128,
element_attr => {
class => ['ngcp_pref_input'],
}

@ -23,6 +23,7 @@ has_field 'display_name' => (
rel => ['tooltip'],
title => ['The person\'s name, which is then used in XMPP contact lists or auto-provisioned phones, and which can be used as network-provided display name in SIP calls.']
},
maxlength => 128,
);
has_field 'alias_numbers' => (

@ -657,6 +657,24 @@ sub update_item {
try {
my $vtype = ref $resource->{$pref};
my $maxlen = 128;
if($vtype eq "") {
if(length($resource->{$pref}) > $maxlen) {
$c->log->error("preference '$pref' exceeds maximum length of $maxlen characters");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Preference '$pref' exceeds maximum length of $maxlen characters");
return;
}
} elsif($vtype eq "ARRAY") {
foreach my $a(@{ $resource->{$pref} }) {
if(length($a) > $maxlen) {
$c->log->error("element in preference '$pref' exceeds maximum length of $maxlen characters");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Element in preference '$pref' exceeds maximum length of $maxlen characters");
return;
}
}
}
if($meta->data_type eq "boolean" && JSON::is_bool($resource->{$pref})) {
$vtype = "";
}

Loading…
Cancel
Save