Initial commit, that adds an additional check to the file being uploaded to the rim page to ensure that it is a valid file.

This commit is contained in:
Cyrus 2020-11-20 09:42:37 -05:00
parent 85be3c2fc8
commit 91fbc7cfd2

View File

@ -60,6 +60,7 @@ public class ReferenceManifestPageController
private static final String BIOS_RELEASE_DATE_FORMAT = "yyyy-MM-dd"; private static final String BIOS_RELEASE_DATE_FORMAT = "yyyy-MM-dd";
private static final String LOG_FILE_PATTERN = "([^\\s]+(\\.(?i)(rimpcr|rimel|bin|log))$)"; private static final String LOG_FILE_PATTERN = "([^\\s]+(\\.(?i)(rimpcr|rimel|bin|log))$)";
private static final String SWID_FILE_PATTERN = "([^\\s]+(\\.(?i)(swidtag))$)";
private final BiosDateValidator biosValidator; private final BiosDateValidator biosValidator;
private final ReferenceManifestManager referenceManifestManager; private final ReferenceManifestManager referenceManifestManager;
@ -188,18 +189,21 @@ public class ReferenceManifestPageController
Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
PageMessages messages = new PageMessages(); PageMessages messages = new PageMessages();
String fileName; String fileName;
Pattern pattern; Pattern logPattern = Pattern.compile(LOG_FILE_PATTERN);
Pattern swidPattern = Pattern.compile(SWID_FILE_PATTERN);
Matcher matcher; Matcher matcher;
boolean supportRIM = false; boolean supportRIM = false;
boolean swidtag = false;
BaseReferenceManifest base; BaseReferenceManifest base;
SupportReferenceManifest support; SupportReferenceManifest support;
// loop through the files // loop through the files
for (MultipartFile file : files) { for (MultipartFile file : files) {
fileName = file.getOriginalFilename(); fileName = file.getOriginalFilename();
pattern = Pattern.compile(LOG_FILE_PATTERN); matcher = logPattern.matcher(fileName);
matcher = pattern.matcher(fileName);
supportRIM = matcher.matches(); supportRIM = matcher.matches();
matcher = swidPattern.matcher(fileName);
swidtag = matcher.matches();
//Parse reference manifests //Parse reference manifests
ReferenceManifest rim = parseRIM(file, supportRIM, messages); ReferenceManifest rim = parseRIM(file, supportRIM, messages);
@ -223,7 +227,7 @@ public class ReferenceManifestPageController
} }
} }
} }
} else { } else if (swidtag) {
base = (BaseReferenceManifest) rim; base = (BaseReferenceManifest) rim;
for (SwidResource swid : base.parseResource()) { for (SwidResource swid : base.parseResource()) {