Skip to content

Commit 526b859

Browse files
committed
Remove native chmod tool execution in tests
`Runtime.getRuntime().exec( "chmod 440 " + ` causes security warnings because it concatenates arguments (there is a risk of argument injection). The argument does not come from untrusted source, but as we can use Java to change a file mode, it is better to remove the `chmod` invocation altogether. `chmod` was necessary before Java 7 as there was no support for changing file modes.
1 parent 8523451 commit 526b859

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/test/java/org/codehaus/plexus/archiver/tar/TarFileAttributesTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.codehaus.plexus.archiver.Archiver;
1010
import org.codehaus.plexus.archiver.UnArchiver;
1111
import org.codehaus.plexus.archiver.util.DefaultArchivedFileSet;
12+
import org.codehaus.plexus.components.io.attributes.AttributeUtils;
1213
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils;
1314
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
1415
import org.codehaus.plexus.util.FileUtils;
@@ -87,8 +88,7 @@ public void testUseAttributesFromTarArchiveInputInTarArchiverOutput()
8788
writer.write( "This is a test file." );
8889
}
8990

90-
int result = Runtime.getRuntime().exec( "chmod 440 " + tempFile.getAbsolutePath() ).waitFor();
91-
assertEquals( 0, result );
91+
AttributeUtils.chmod(tempFile, 0440);
9292

9393
TarArchiver tarArchiver = getPosixCompliantTarArchiver();
9494

@@ -153,9 +153,7 @@ public void testUseDetectedFileAttributes()
153153
writer.write( "This is a test file." );
154154
}
155155

156-
int result = Runtime.getRuntime().exec( "chmod 440 " + tempFile.getAbsolutePath() ).waitFor();
157-
158-
assertEquals( 0, result );
156+
AttributeUtils.chmod(tempFile, 0440);
159157

160158
PlexusIoResourceAttributes fileAttributes = PlexusIoResourceAttributeUtils.getFileAttributes( tempFile );
161159

@@ -214,8 +212,7 @@ public void testOverrideDetectedFileAttributes()
214212
writer.write( "This is a test file." );
215213
}
216214

217-
int result = Runtime.getRuntime().exec( "chmod 440 " + tempFile.getAbsolutePath() ).waitFor();
218-
assertEquals( 0, result );
215+
AttributeUtils.chmod(tempFile, 0440);
219216

220217
TarArchiver tarArchiver = getPosixCompliantTarArchiver();
221218

@@ -272,8 +269,7 @@ public void testOverrideDetectedFileAttributesUsingFileMode()
272269
writer.write( "This is a test file." );
273270
}
274271

275-
int result = Runtime.getRuntime().exec( "chmod 440 " + tempFile.getAbsolutePath() ).waitFor();
276-
assertEquals( 0, result );
272+
AttributeUtils.chmod(tempFile, 0440);
277273

278274
TarArchiver tarArchiver = getPosixCompliantTarArchiver();
279275

0 commit comments

Comments
 (0)