Skip to content

Commit

Permalink
Merge pull request #60 from jfdenise/main
Browse files Browse the repository at this point in the history
Fix hash computation, resist to badly formatted XML
  • Loading branch information
jfdenise authored Apr 2, 2024
2 parents 48b8c12 + c394b68 commit 0f625cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 16 additions & 1 deletion core/src/main/java/org/wildfly/glow/DeploymentScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
import java.util.stream.Collectors;

import static org.objectweb.asm.Opcodes.ASM9;
import org.wildfly.glow.error.ErrorLevel;
import org.wildfly.glow.error.IdentifiedError;

public class DeploymentScanner implements AutoCloseable {

Expand Down Expand Up @@ -629,7 +631,20 @@ Set<Layer> inspectDeployment(Path rootPath,
if (k.startsWith(LayerMetadata.XML_PATH)) {
ParsedRule rule = inspector.extractParsedRule(val);
rule.iterateMatchedPaths((path, values) -> {
Utils.applyXPath(path, values.get(0).getValue(), values.size() == 1 ? null : values.get(1).getValue(), consumer, l);
try {
Utils.applyXPath(path, values.get(0).getValue(), values.size() == 1 ? null : values.get(1).getValue(), consumer, l);
} catch(Exception ex) {
String id = "invalidXML" + path;
boolean allreadySet = false;
for (IdentifiedError err : ctx.errorSession.getErrors()) {
if (id.equals(err.getId())) {
allreadySet = true;
}
}
if (!allreadySet) {
ctx.errorSession.addError(new IdentifiedError(id, "Exception parsing " + path + ": " + ex, ErrorLevel.WARN));
}
}
});
} else if (k.startsWith(LayerMetadata.PROPERTIES_FILE_MATCH)) {
ParsedRule parsedRule = inspector.extractParsedRule(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import io.fabric8.openshift.api.model.RouteTargetReference;
import io.fabric8.openshift.api.model.TLSConfig;
import io.fabric8.openshift.client.OpenShiftClient;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.MessageDigest;
Expand Down Expand Up @@ -394,11 +395,15 @@ private static Map<String, String> createLabels(Path target, Path provisioning,
private static String doServerImageBuild(GlowMessageWriter writer, Path target, OpenShiftClient osClient,
Map<String, String> buildExtraEnv,
OpenShiftConfiguration config) throws Exception {
// To compute a hash we need build time env variables and channel version.
// To compute a hash we need build time env variables
StringBuilder contentBuilder = new StringBuilder();
Path provisioning = target.resolve("galleon").resolve("provisioning.xml");
byte[] content = Files.readAllBytes(provisioning);
contentBuilder.append(Files.readString(provisioning, Charset.forName("UTF-8")));
for (Entry<String, String> entry : buildExtraEnv.entrySet()) {
contentBuilder.append(entry.getKey() + "=" + entry.getValue());
}
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] encodedhash = digest.digest(content);
byte[] encodedhash = digest.digest(contentBuilder.toString().getBytes());
String key = bytesToHex(encodedhash);
String serverImageName = config.getServerImageNameRadical() + key;

Expand Down

0 comments on commit 0f625cb

Please sign in to comment.