changeset 3957:cd853175b58c

6992523: FindBugs scan - Malicious code vulnerability Warnings in com.sun.media.sound.* Reviewed-by: alexp
author amenkov
date Wed, 06 Apr 2011 15:12:33 +0400
parents 6128bcca6403
children f7eb08bf41e5
files src/share/classes/com/sun/media/sound/DLSInstrument.java src/share/classes/com/sun/media/sound/DLSSample.java src/share/classes/com/sun/media/sound/ModelConnectionBlock.java src/share/classes/com/sun/media/sound/SoftChannel.java src/share/classes/com/sun/media/sound/SoftInstrument.java src/share/classes/com/sun/media/sound/SoftMixingDataLine.java src/share/classes/com/sun/media/sound/SoftProvider.java src/share/classes/com/sun/media/sound/SoftTuning.java
diffstat 8 files changed, 26 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/media/sound/DLSInstrument.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/DLSSample.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/ModelConnectionBlock.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/SoftChannel.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/SoftInstrument.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/SoftMixingDataLine.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/SoftProvider.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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/src/share/classes/com/sun/media/sound/SoftTuning.java	Wed Apr 06 15:07:23 2011 +0400
+++ b/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) {