diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index dfa145da..9e6c34b9 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -113,10 +113,10 @@ public void addModification(VariableModification modification) { /** * Returns all modifications that are set for this modifiable variable. * - * @return The list of modifications or null if no modifications are set + * @return A copy of the list of modifications or null if no modifications are set */ public LinkedList> getModifications() { - return modifications; + return modifications == null ? null : new LinkedList<>(modifications); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index 46e59044..bff6faf2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -51,8 +51,8 @@ private ByteArrayAppendValueModification() { */ public ByteArrayAppendValueModification(byte[] bytesToAppend) { super(); - this.bytesToAppend = - Objects.requireNonNull(bytesToAppend, "bytesToAppend must not be null"); + Objects.requireNonNull(bytesToAppend, "bytesToAppend must not be null"); + this.bytesToAppend = bytesToAppend.clone(); } /** @@ -105,7 +105,7 @@ protected byte[] modifyImplementationHook(byte[] input) { * @return The bytes to append */ public byte[] getBytesToAppend() { - return bytesToAppend; + return bytesToAppend == null ? null : bytesToAppend.clone(); } /** @@ -115,8 +115,8 @@ public byte[] getBytesToAppend() { * @throws NullPointerException if bytesToAppend is null */ public void setBytesToAppend(byte[] bytesToAppend) { - this.bytesToAppend = - Objects.requireNonNull(bytesToAppend, "BytesToAppend must not be null"); + Objects.requireNonNull(bytesToAppend, "BytesToAppend must not be null"); + this.bytesToAppend = bytesToAppend.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index 28b4a6b1..3cb13342 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -44,8 +44,8 @@ private ByteArrayExplicitValueModification() { */ public ByteArrayExplicitValueModification(byte[] explicitValue) { super(); - this.explicitValue = - Objects.requireNonNull(explicitValue, "ExplicitValue must not be null"); + Objects.requireNonNull(explicitValue, "ExplicitValue must not be null"); + this.explicitValue = explicitValue.clone(); } /** @@ -91,7 +91,7 @@ protected byte[] modifyImplementationHook(byte[] input) { * @return The explicit byte array */ public byte[] getExplicitValue() { - return explicitValue; + return explicitValue == null ? null : explicitValue.clone(); } /** @@ -100,8 +100,8 @@ public byte[] getExplicitValue() { * @param explicitValue The new explicit byte array to use */ public void setExplicitValue(byte[] explicitValue) { - this.explicitValue = - Objects.requireNonNull(explicitValue, "ExplicitValue must not be null"); + Objects.requireNonNull(explicitValue, "ExplicitValue must not be null"); + this.explicitValue = explicitValue.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index 2419abcd..3c37dbe0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -56,8 +56,8 @@ private ByteArrayInsertValueModification() { */ public ByteArrayInsertValueModification(byte[] bytesToInsert, int startPosition) { super(); - this.bytesToInsert = - Objects.requireNonNull(bytesToInsert, "BytesToInsert must not be null"); + Objects.requireNonNull(bytesToInsert, "BytesToInsert must not be null"); + this.bytesToInsert = bytesToInsert.clone(); this.startPosition = startPosition; } @@ -129,7 +129,7 @@ protected byte[] modifyImplementationHook(byte[] input) { * @return The bytes to insert */ public byte[] getBytesToInsert() { - return bytesToInsert; + return bytesToInsert == null ? null : bytesToInsert.clone(); } /** @@ -139,8 +139,8 @@ public byte[] getBytesToInsert() { * @throws NullPointerException if bytesToInsert is null */ public void setBytesToInsert(byte[] bytesToInsert) { - this.bytesToInsert = - Objects.requireNonNull(bytesToInsert, "bytesToInsert must not be null"); + Objects.requireNonNull(bytesToInsert, "bytesToInsert must not be null"); + this.bytesToInsert = bytesToInsert.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 3f32c70d..f017d0a5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -52,8 +52,8 @@ private ByteArrayPrependValueModification() { */ public ByteArrayPrependValueModification(byte[] bytesToPrepend) { super(); - this.bytesToPrepend = - Objects.requireNonNull(bytesToPrepend, "bytesToPrepend must not be null"); + Objects.requireNonNull(bytesToPrepend, "bytesToPrepend must not be null"); + this.bytesToPrepend = bytesToPrepend.clone(); } /** @@ -107,7 +107,7 @@ protected byte[] modifyImplementationHook(byte[] input) { * @return The bytes to prepend */ public byte[] getBytesToPrepend() { - return bytesToPrepend; + return bytesToPrepend == null ? null : bytesToPrepend.clone(); } /** @@ -117,8 +117,8 @@ public byte[] getBytesToPrepend() { * @throws NullPointerException if bytesToPrepend is null */ public void setBytesToPrepend(byte[] bytesToPrepend) { - this.bytesToPrepend = - Objects.requireNonNull(bytesToPrepend, "bytesToPrepend must not be null"); + Objects.requireNonNull(bytesToPrepend, "bytesToPrepend must not be null"); + this.bytesToPrepend = bytesToPrepend.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index ab301c23..00fb42d2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -45,7 +45,8 @@ private ByteArrayShuffleModification() { */ public ByteArrayShuffleModification(int[] shuffle) { super(); - this.shuffle = Objects.requireNonNull(shuffle, "Shuffle pattern must not be null"); + Objects.requireNonNull(shuffle, "Shuffle pattern must not be null"); + this.shuffle = shuffle.clone(); } /** @@ -113,7 +114,7 @@ protected byte[] modifyImplementationHook(byte[] input) { * @return The int array containing the shuffle pattern */ public int[] getShuffle() { - return shuffle; + return shuffle == null ? null : shuffle.clone(); } /** @@ -123,7 +124,8 @@ public int[] getShuffle() { * @throws NullPointerException if shuffle is null */ public void setShuffle(int[] shuffle) { - this.shuffle = Objects.requireNonNull(shuffle, "Shuffle pattern must not be null"); + Objects.requireNonNull(shuffle, "Shuffle pattern must not be null"); + this.shuffle = shuffle.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index f039c729..dd0e16b2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -49,7 +49,8 @@ private ByteArrayXorModification() { */ public ByteArrayXorModification(byte[] xor, int startPosition) { super(); - this.xor = Objects.requireNonNull(xor, "XOR array must not be null"); + Objects.requireNonNull(xor, "XOR array must not be null"); + this.xor = xor.clone(); this.startPosition = startPosition; } @@ -126,10 +127,10 @@ protected byte[] modifyImplementationHook(byte[] input) { /** * Gets the byte array used for the XOR operation. * - * @return The XOR byte array + * @return A copy of the XOR byte array */ public byte[] getXor() { - return xor; + return xor == null ? null : xor.clone(); } /** @@ -138,7 +139,7 @@ public byte[] getXor() { * @param xor The new XOR byte array */ public void setXor(byte[] xor) { - this.xor = xor; + this.xor = xor == null ? null : xor.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index 5aff26db..a9547288 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -59,7 +59,7 @@ public ModifiableByteArray() { */ public ModifiableByteArray(byte[] originalValue) { super(); - this.originalValue = originalValue; + this.originalValue = originalValue == null ? null : originalValue.clone(); } /** @@ -99,7 +99,7 @@ public ModifiableByteArray createCopy() { @Override @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) public byte[] getOriginalValue() { - return originalValue; + return originalValue == null ? null : originalValue.clone(); } /** @@ -109,7 +109,7 @@ public byte[] getOriginalValue() { */ @Override public void setOriginalValue(byte[] originalValue) { - this.originalValue = originalValue; + this.originalValue = originalValue == null ? null : originalValue.clone(); } /** @@ -121,7 +121,7 @@ public void setOriginalValue(byte[] originalValue) { */ @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) public byte[] getAssertEquals() { - return assertEquals; + return assertEquals == null ? null : assertEquals.clone(); } /** @@ -130,7 +130,7 @@ public byte[] getAssertEquals() { * @param assertEquals The expected byte array value */ public void setAssertEquals(byte[] assertEquals) { - this.assertEquals = assertEquals; + this.assertEquals = assertEquals == null ? null : assertEquals.clone(); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java index af2400ae..cfcc76a4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java @@ -44,7 +44,7 @@ private ComparableByteArray() { */ public ComparableByteArray(byte[] array) { super(); - this.array = array; + this.array = array == null ? null : array.clone(); } /** @@ -53,7 +53,7 @@ public ComparableByteArray(byte[] array) { * @return A the wrapped byte array */ public byte[] getArray() { - return array; + return array == null ? null : array.clone(); } /** @@ -62,7 +62,7 @@ public byte[] getArray() { * @param array The new byte array to wrap */ public void setArray(byte[] array) { - this.array = array; + this.array = array == null ? null : array.clone(); } /**