/dev/null permissions were modified when using sudo rights.
This fixes this bug during decompression.

More importantly, this patch  adds a test, triggered in TravisCI,
ensuring unaltered /dev/null permissions.
This commit is contained in:
Yann Collet 2019-11-25 10:35:36 -08:00
parent 762a0dfc45
commit 7aaac3f69c
3 changed files with 31 additions and 11 deletions

View File

@ -34,7 +34,8 @@ matrix:
- name: make test (complete) - name: make test (complete)
script: script:
- make test # DEVNULLRIGHTS : will request sudo rights to test permissions on /dev/null
- DEVNULLRIGHTS=test make test
- name: gcc-6 + gcc-7 compilation - name: gcc-6 + gcc-7 compilation
script: script:

View File

@ -609,7 +609,10 @@ FIO_openDstFile(FIO_prefs_t* const prefs,
{ FILE* const f = fopen( dstFileName, "wb" ); { FILE* const f = fopen( dstFileName, "wb" );
if (f == NULL) { if (f == NULL) {
DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno)); DISPLAYLEVEL(1, "zstd: %s: %s\n", dstFileName, strerror(errno));
} else if(srcFileName != NULL && strcmp (srcFileName, stdinmark)) { } else if (srcFileName != NULL
&& strcmp (srcFileName, stdinmark)
&& strcmp(dstFileName, nulmark) ) {
/* reduce rights on newly created dst file while compression is ongoing */
chmod(dstFileName, 00600); chmod(dstFileName, 00600);
} }
return f; return f;
@ -1393,7 +1396,7 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
assert(ress.srcFile != NULL); assert(ress.srcFile != NULL);
if (ress.dstFile == NULL) { if (ress.dstFile == NULL) {
closeDstFile = 1; closeDstFile = 1;
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: opening dst: %s", dstFileName); DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: opening dst: %s \n", dstFileName);
ress.dstFile = FIO_openDstFile(prefs, srcFileName, dstFileName); ress.dstFile = FIO_openDstFile(prefs, srcFileName, dstFileName);
if (ress.dstFile==NULL) return 1; /* could not open dstFileName */ if (ress.dstFile==NULL) return 1; /* could not open dstFileName */
/* Must only be added after FIO_openDstFile() succeeds. /* Must only be added after FIO_openDstFile() succeeds.
@ -1415,6 +1418,7 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
clearHandler(); clearHandler();
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: closing dst: %s \n", dstFileName);
if (fclose(dstFile)) { /* error closing dstFile */ if (fclose(dstFile)) { /* error closing dstFile */
DISPLAYLEVEL(1, "zstd: %s: %s \n", dstFileName, strerror(errno)); DISPLAYLEVEL(1, "zstd: %s: %s \n", dstFileName, strerror(errno));
result=1; result=1;
@ -1427,7 +1431,10 @@ static int FIO_compressFilename_dstFile(FIO_prefs_t* const prefs,
} else if ( strcmp(dstFileName, stdoutmark) } else if ( strcmp(dstFileName, stdoutmark)
&& strcmp(dstFileName, nulmark) && strcmp(dstFileName, nulmark)
&& transfer_permissions) { && transfer_permissions) {
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: transfering permissions into dst: %s \n", dstFileName);
UTIL_setFileStat(dstFileName, &statbuf); UTIL_setFileStat(dstFileName, &statbuf);
} else {
DISPLAYLEVEL(6, "FIO_compressFilename_dstFile: do not transfer permissions into dst: %s \n", dstFileName);
} }
} }
@ -1462,6 +1469,7 @@ FIO_compressFilename_srcFile(FIO_prefs_t* const prefs,
int compressionLevel) int compressionLevel)
{ {
int result; int result;
DISPLAYLEVEL(6, "FIO_compressFilename_srcFile: %s \n", srcFileName);
/* ensure src is not a directory */ /* ensure src is not a directory */
if (UTIL_isDirectory(srcFileName)) { if (UTIL_isDirectory(srcFileName)) {

View File

@ -220,13 +220,12 @@ $ZSTD tmp -c --compress-literals -19 | $ZSTD -t
$ZSTD -b --fast=1 -i0e1 tmp --compress-literals $ZSTD -b --fast=1 -i0e1 tmp --compress-literals
$ZSTD -b --fast=1 -i0e1 tmp --no-compress-literals $ZSTD -b --fast=1 -i0e1 tmp --no-compress-literals
println "test: --exclude-compressed flag" println "\n===> --exclude-compressed flag"
rm -rf precompressedFilterTestDir rm -rf precompressedFilterTestDir
mkdir -p precompressedFilterTestDir mkdir -p precompressedFilterTestDir
./datagen $size > precompressedFilterTestDir/input.5 ./datagen $size > precompressedFilterTestDir/input.5
./datagen $size > precompressedFilterTestDir/input.6 ./datagen $size > precompressedFilterTestDir/input.6
$ZSTD --exclude-compressed --long --rm -r precompressedFilterTestDir $ZSTD --exclude-compressed --long --rm -r precompressedFilterTestDir
sleep 5
./datagen $size > precompressedFilterTestDir/input.7 ./datagen $size > precompressedFilterTestDir/input.7
./datagen $size > precompressedFilterTestDir/input.8 ./datagen $size > precompressedFilterTestDir/input.8
$ZSTD --exclude-compressed --long --rm -r precompressedFilterTestDir $ZSTD --exclude-compressed --long --rm -r precompressedFilterTestDir
@ -251,7 +250,7 @@ test -f precompressedFilterTestDir/input.5.zst.zst
test -f precompressedFilterTestDir/input.6.zst.zst test -f precompressedFilterTestDir/input.6.zst.zst
println "Test completed" println "Test completed"
println "test : file removal" println "\n===> file removal"
$ZSTD -f --rm tmp $ZSTD -f --rm tmp
test ! -f tmp # tmp should no longer be present test ! -f tmp # tmp should no longer be present
$ZSTD -f -d --rm tmp.zst $ZSTD -f -d --rm tmp.zst
@ -279,12 +278,15 @@ test -f tmp.zst # destination file should still be present
rm -rf tmp* # may also erase tmp* directory from previous failed run rm -rf tmp* # may also erase tmp* directory from previous failed run
println "\n===> decompression only tests " println "\n===> decompression only tests "
dd bs=1 count=1048576 if=/dev/zero of=tmp # the following test verifies that the decoder is compatible with RLE as first block
# older versions of zstd cli are not able to decode such corner case.
# As a consequence, the zstd cli do not generate them, to maintain compatibility with older versions.
dd bs=1048576 count=1 if=/dev/zero of=tmp
$ZSTD -d -o tmp1 "$TESTDIR/golden-decompression/rle-first-block.zst" $ZSTD -d -o tmp1 "$TESTDIR/golden-decompression/rle-first-block.zst"
$DIFF -s tmp1 tmp $DIFF -s tmp1 tmp
rm tmp* rm tmp*
println "test : compress multiple files" println "\m===> compress multiple files"
println hello > tmp1 println hello > tmp1
println world > tmp2 println world > tmp2
$ZSTD tmp1 tmp2 -o "$INTOVOID" -f $ZSTD tmp1 tmp2 -o "$INTOVOID" -f
@ -306,7 +308,17 @@ if [ "$?" -eq 139 ]; then
fi fi
rm tmp* rm tmp*
println "test : compress multiple files into an output directory, --output-dir-flat" if [ -n "$DEVNULLRIGHTS" ]
then
# these tests requires sudo rights, which is uncommon.
# they are only triggered if DEVNULLRIGHTS macro is defined.
println "\n===> checking /dev/null permissions are unaltered "
./datagen > tmp
sudo $ZSTD tmp -o $INTOVOID # sudo rights could modify /dev/null permissions
ls -las $INTOVOID | grep "rw-rw-rw-"
fi
println "\n===> compress multiple files into an output directory, --output-dir-flat"
println henlo > tmp1 println henlo > tmp1
mkdir tmpInputTestDir mkdir tmpInputTestDir
mkdir tmpInputTestDir/we mkdir tmpInputTestDir/we
@ -352,7 +364,6 @@ $ZSTD -dcf tmp1
println "\n===> frame concatenation " println "\n===> frame concatenation "
println "hello " > hello.tmp println "hello " > hello.tmp
println "world!" > world.tmp println "world!" > world.tmp
cat hello.tmp world.tmp > helloworld.tmp cat hello.tmp world.tmp > helloworld.tmp