aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-05 15:24:52 (EDT)
committerHenrik Lynggaard Hansen2012-07-05 15:24:52 (EDT)
commit526331acb053d424ddc746d19ecb18aa1dc0ae7b (patch)
tree8273384386658e607c07e1f21434a3e53806c639
parentb3f23e82c67f65adc91ce3f463f3ceb272694b80 (diff)
downloadorg.eclipse.hudson.core-526331acb053d424ddc746d19ecb18aa1dc0ae7b.zip
org.eclipse.hudson.core-526331acb053d424ddc746d19ecb18aa1dc0ae7b.tar.gz
org.eclipse.hudson.core-526331acb053d424ddc746d19ecb18aa1dc0ae7b.tar.bz2
Move security check to after null check to avoid NPErefs/changes/44/6644/1
Change-Id: If50d5bbc0cddf4eae8dbd80cd9be444ff982db23 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/FilePath.java27
1 files changed, 16 insertions, 11 deletions
diff --git a/hudson-core/src/main/java/hudson/FilePath.java b/hudson-core/src/main/java/hudson/FilePath.java
index 98bd97d..d0845b4 100644
--- a/hudson-core/src/main/java/hudson/FilePath.java
+++ b/hudson-core/src/main/java/hudson/FilePath.java
@@ -1815,30 +1815,35 @@ public final class FilePath implements Serializable {
* Otherwise, the relative path is expected to be pointing to a directory.
*/
public FormValidation validateRelativePath(String value, boolean errorIfNotExist, boolean expectingFile) throws IOException {
- AbstractProject subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
- subject.checkPermission(Item.CONFIGURE);
-
+ AbstractProject subject = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
value = fixEmpty(value);
// none entered yet, or something is seriously wrong
- if(value==null || (AbstractProject<?,?>)subject ==null) return FormValidation.ok();
+ if (value == null || (AbstractProject<?,?>) subject == null) {
+ return FormValidation.ok();
+ }
+ subject.checkPermission(Item.CONFIGURE);
// a common mistake is to use wildcard
- if(value.contains("*")) return FormValidation.error(Messages.FilePath_validateRelativePath_wildcardNotAllowed());
+ if (value.contains("*")) {
+ return FormValidation.error(Messages.FilePath_validateRelativePath_wildcardNotAllowed());
+ }
try {
- if(!exists()) // no base directory. can't check
+ // no base directory. can't check
+ if (!exists()) {
return FormValidation.ok();
-
+ }
+
FilePath path = child(value);
- if(path.exists()) {
+ if (path.exists()) {
if (expectingFile) {
- if(!path.isDirectory())
+ if (!path.isDirectory())
return FormValidation.ok();
else
return FormValidation.error(Messages.FilePath_validateRelativePath_notFile(value));
} else {
- if(path.isDirectory())
+ if (path.isDirectory())
return FormValidation.ok();
else
return FormValidation.error(Messages.FilePath_validateRelativePath_notDirectory(value));
@@ -1847,7 +1852,7 @@ public final class FilePath implements Serializable {
String msg = expectingFile ? Messages.FilePath_validateRelativePath_noSuchFile(value) :
Messages.FilePath_validateRelativePath_noSuchDirectory(value);
- if(errorIfNotExist) return FormValidation.error(msg);
+ if (errorIfNotExist) return FormValidation.error(msg);
else return FormValidation.warning(msg);
} catch (InterruptedException e) {
return FormValidation.ok();