6992523: FindBugs scan - Malicious code vulnerability Warnings in com.sun.media.sound.*
authoramenkov
Wed, 06 Apr 2011 15:12:33 +0400
changeset 9215 cab45ca6ab44
parent 9214 237acaa608d5
child 9216 d102bd3f513c
6992523: FindBugs scan - Malicious code vulnerability Warnings in com.sun.media.sound.* Reviewed-by: alexp
jdk/src/share/classes/com/sun/media/sound/DLSInstrument.java
jdk/src/share/classes/com/sun/media/sound/DLSSample.java
jdk/src/share/classes/com/sun/media/sound/ModelConnectionBlock.java
jdk/src/share/classes/com/sun/media/sound/SoftChannel.java
jdk/src/share/classes/com/sun/media/sound/SoftInstrument.java
jdk/src/share/classes/com/sun/media/sound/SoftMixingDataLine.java
jdk/src/share/classes/com/sun/media/sound/SoftProvider.java
jdk/src/share/classes/com/sun/media/sound/SoftTuning.java
--- a/jdk/src/share/classes/com/sun/media/sound/DLSInstrument.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/DLSInstrument.java	Wed Apr 06 15:12:33 2011 +0400
@@ -25,6 +25,7 @@
 package com.sun.media.sound;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -439,10 +440,10 @@
     }
 
     public byte[] getGuid() {
-        return guid;
+        return guid == null ? null : Arrays.copyOf(guid, guid.length);
     }
 
     public void setGuid(byte[] guid) {
-        this.guid = guid;
+        this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);
     }
 }
--- a/jdk/src/share/classes/com/sun/media/sound/DLSSample.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/DLSSample.java	Wed Apr 06 15:12:33 2011 +0400
@@ -25,6 +25,7 @@
 package com.sun.media.sound;
 
 import java.io.InputStream;
+import java.util.Arrays;
 import javax.sound.midi.Soundbank;
 import javax.sound.midi.SoundbankResource;
 import javax.sound.sampled.AudioFormat;
@@ -113,10 +114,10 @@
     }
 
     public byte[] getGuid() {
-        return guid;
+        return guid == null ? null : Arrays.copyOf(guid, guid.length);
     }
 
     public void setGuid(byte[] guid) {
-        this.guid = guid;
+        this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);
     }
 }
--- a/jdk/src/share/classes/com/sun/media/sound/ModelConnectionBlock.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/ModelConnectionBlock.java	Wed Apr 06 15:12:33 2011 +0400
@@ -24,6 +24,8 @@
  */
 package com.sun.media.sound;
 
+import java.util.Arrays;
+
 /**
  * Connection blocks are used to connect source variable
  * to a destination variable.
@@ -117,19 +119,17 @@
     }
 
     public ModelSource[] getSources() {
-        return sources;
+        return Arrays.copyOf(sources, sources.length);
     }
 
     public void setSources(ModelSource[] source) {
-        this.sources = source;
+        this.sources = source == null ? no_sources : Arrays.copyOf(source, source.length);
     }
 
     public void addSource(ModelSource source) {
         ModelSource[] oldsources = sources;
         sources = new ModelSource[oldsources.length + 1];
-        for (int i = 0; i < oldsources.length; i++) {
-            sources[i] = oldsources[i];
-        }
+        System.arraycopy(oldsources, 0, sources, 0, oldsources.length);
         sources[sources.length - 1] = source;
     }
 }
--- a/jdk/src/share/classes/com/sun/media/sound/SoftChannel.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftChannel.java	Wed Apr 06 15:12:33 2011 +0400
@@ -503,7 +503,7 @@
             firstVoice = true;
             voiceNo = 0;
 
-            int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0));
+            int tunedKey = (int)(Math.round(tuning.getTuning(noteNumber)/100.0));
             play_noteNumber = noteNumber;
             play_velocity = velocity;
             play_delay = delay;
@@ -607,7 +607,7 @@
             firstVoice = true;
             voiceNo = 0;
 
-            int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0));
+            int tunedKey = (int)(Math.round(tuning.getTuning(noteNumber)/100.0));
             play_noteNumber = noteNumber;
             play_velocity = lastVelocity[noteNumber];
             play_releasetriggered = true;
@@ -632,7 +632,7 @@
         int delay = play_delay;
         boolean releasetriggered = play_releasetriggered;
 
-        SoftPerformer p = current_instrument.getPerformers()[performerIndex];
+        SoftPerformer p = current_instrument.getPerformer(performerIndex);
 
         if (firstVoice) {
             firstVoice = false;
--- a/jdk/src/share/classes/com/sun/media/sound/SoftInstrument.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftInstrument.java	Wed Apr 06 15:12:33 2011 +0400
@@ -76,7 +76,12 @@
         return data;
     }
 
+    /* am: currently getPerformers() is not used (replaced with getPerformer(int))
     public SoftPerformer[] getPerformers() {
         return performers;
     }
+    */
+    public SoftPerformer getPerformer(int index) {
+        return performers[index];
+    }
 }
--- a/jdk/src/share/classes/com/sun/media/sound/SoftMixingDataLine.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftMixingDataLine.java	Wed Apr 06 15:12:33 2011 +0400
@@ -505,7 +505,7 @@
     }
 
     public Control[] getControls() {
-        return controls;
+        return Arrays.copyOf(controls, controls.length);
     }
 
     public boolean isControlSupported(Type control) {
--- a/jdk/src/share/classes/com/sun/media/sound/SoftProvider.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftProvider.java	Wed Apr 06 15:12:33 2011 +0400
@@ -24,6 +24,7 @@
  */
 package com.sun.media.sound;
 
+import java.util.Arrays;
 import javax.sound.midi.MidiDevice;
 import javax.sound.midi.MidiDevice.Info;
 import javax.sound.midi.spi.MidiDeviceProvider;
@@ -39,7 +40,7 @@
     private static Info[] softinfos = {softinfo};
 
     public MidiDevice.Info[] getDeviceInfo() {
-        return softinfos;
+        return Arrays.copyOf(softinfos, softinfos.length);
     }
 
     public MidiDevice getDevice(MidiDevice.Info info) {
--- a/jdk/src/share/classes/com/sun/media/sound/SoftTuning.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftTuning.java	Wed Apr 06 15:12:33 2011 +0400
@@ -25,6 +25,7 @@
 package com.sun.media.sound;
 
 import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
 
 import javax.sound.midi.Patch;
 
@@ -234,8 +235,10 @@
         }
     }
 
+    // am: getTuning(int) is more effective.
+    // currently getTuning() is used only by tests
     public double[] getTuning() {
-        return tuning;
+        return Arrays.copyOf(tuning, tuning.length);
     }
 
     public double getTuning(int noteNumber) {