Skip to content

Commit

Permalink
Fix #264: made ListIndexConverter more robust as to spoofed/wrong values
Browse files Browse the repository at this point in the history
  • Loading branch information
Bauke Scholtz committed Jun 11, 2016
1 parent d80a0a9 commit d0e0200
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/omnifaces/converter/ListIndexConverter.java
Expand Up @@ -52,6 +52,9 @@
@FacesConverter("omnifaces.ListIndexConverter")
public class ListIndexConverter implements Converter {

private static final String ERROR_LIST_INDEX =
"Could not determine index for value ''{0}'' in component {1}.";

private static final String ERROR_LIST_INDEX_BOUNDS =
"Index {0} for value {1} in component {2} is out of bounds.";

Expand All @@ -62,7 +65,16 @@ public class ListIndexConverter implements Converter {

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
int index = Integer.valueOf(value);
int index;

try {
index = Integer.valueOf(value);
}
catch (NumberFormatException e) {
throw new ConverterException(
createError(ERROR_LIST_INDEX, value, component.getClientId(context)), e);
}

if (index < 0 || index >= list.size()) {
throw new ConverterException(
createError(ERROR_LIST_INDEX_BOUNDS, index, value, component.getClientId(context))
Expand Down

0 comments on commit d0e0200

Please sign in to comment.