mirror of
https://github.com/AltraMayor/f3.git
synced 2025-08-03 18:46:00 -04:00
Merge pull request #187 from Al2Klimov/hardening
Hardening f3write and f3read
This commit is contained in:
commit
283f386448
77
.github/workflows/test.yml
vendored
77
.github/workflows/test.yml
vendored
@ -9,26 +9,60 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Linux:
|
Linux:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
volume:
|
||||||
|
- /tmp
|
||||||
|
- .
|
||||||
|
- /
|
||||||
|
asroot:
|
||||||
|
- name: ''
|
||||||
|
sudo: ''
|
||||||
|
- name: ' as root'
|
||||||
|
sudo: 'sudo '
|
||||||
|
|
||||||
|
name: Linux ${{ matrix.volume }}${{ matrix.asroot.name }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: sudo apt-get install -y libparted-dev libudev-dev
|
- run: sudo apt-get install -y libparted-dev libudev-dev
|
||||||
- run: make all extra
|
- run: make all extra
|
||||||
|
|
||||||
|
- if: matrix.volume == '/'
|
||||||
|
run: sudo chmod a+w /
|
||||||
|
|
||||||
- run: ./f3write -V
|
- run: ./f3write -V
|
||||||
- run: ./f3write --help
|
- run: ./f3write --help
|
||||||
- run: ./f3write -s 2 -e 4 -w 50000 /tmp
|
- run: ${{ matrix.asroot.sudo }}./f3write -s 2 -e 4 -w 50000 ${{ matrix.volume }}
|
||||||
|
|
||||||
- run: stat /tmp/2.h2w
|
- run: stat ${{ matrix.volume }}/2.h2w
|
||||||
- run: stat /tmp/3.h2w
|
- run: stat ${{ matrix.volume }}/3.h2w
|
||||||
- run: stat /tmp/4.h2w
|
- run: stat ${{ matrix.volume }}/4.h2w
|
||||||
|
|
||||||
- run: ./f3read -V
|
- run: ./f3read -V
|
||||||
- run: ./f3read --help
|
- run: ./f3read --help
|
||||||
- run: ./f3read -s 2 -e 4 -r 50000 /tmp
|
- run: ${{ matrix.asroot.sudo }}./f3read -s 2 -e 4 -r 50000 ${{ matrix.volume }}
|
||||||
|
|
||||||
MacOS:
|
MacOS:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
volume:
|
||||||
|
- /tmp
|
||||||
|
- .
|
||||||
|
# MacOS denies `sudo chmod a+w /`
|
||||||
|
#- /
|
||||||
|
asroot:
|
||||||
|
- name: ''
|
||||||
|
sudo: ''
|
||||||
|
- name: ' as root'
|
||||||
|
sudo: 'sudo '
|
||||||
|
|
||||||
|
name: MacOS ${{ matrix.volume }}${{ matrix.asroot.name }}
|
||||||
runs-on: macos-12
|
runs-on: macos-12
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: brew install argp-standalone
|
- run: brew install argp-standalone
|
||||||
@ -36,18 +70,31 @@ jobs:
|
|||||||
|
|
||||||
- run: ./f3write -V
|
- run: ./f3write -V
|
||||||
- run: ./f3write --help
|
- run: ./f3write --help
|
||||||
- run: ./f3write -s 2 -e 4 -w 50000 /tmp
|
- run: ${{ matrix.asroot.sudo }}./f3write -s 2 -e 4 -w 50000 ${{ matrix.volume }}
|
||||||
|
|
||||||
- run: stat /tmp/2.h2w
|
- run: stat ${{ matrix.volume }}/2.h2w
|
||||||
- run: stat /tmp/3.h2w
|
- run: stat ${{ matrix.volume }}/3.h2w
|
||||||
- run: stat /tmp/4.h2w
|
- run: stat ${{ matrix.volume }}/4.h2w
|
||||||
|
|
||||||
- run: ./f3read -V
|
- run: ./f3read -V
|
||||||
- run: ./f3read --help
|
- run: ./f3read --help
|
||||||
- run: ./f3read -s 2 -e 4 -r 50000 /tmp
|
- run: ${{ matrix.asroot.sudo }}./f3read -s 2 -e 4 -r 50000 ${{ matrix.volume }}
|
||||||
|
|
||||||
Cygwin:
|
Cygwin:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
volume:
|
||||||
|
- cygwin: /cygdrive/c
|
||||||
|
windows: 'C:'
|
||||||
|
- cygwin: .
|
||||||
|
windows: .
|
||||||
|
- cygwin: /
|
||||||
|
windows: 'C:\cygwin'
|
||||||
|
|
||||||
|
name: Cygwin ${{ matrix.volume.cygwin }}
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
@ -59,12 +106,12 @@ jobs:
|
|||||||
|
|
||||||
- run: '& .\f3write.exe -V'
|
- run: '& .\f3write.exe -V'
|
||||||
- run: '& .\f3write.exe --help'
|
- run: '& .\f3write.exe --help'
|
||||||
- run: '& .\f3write.exe -s 2 -e 4 -w 50000 /cygdrive/c'
|
- run: '& .\f3write.exe -s 2 -e 4 -w 50000 ${{ matrix.volume.cygwin }}'
|
||||||
|
|
||||||
- run: 'Get-Item C:\2.h2w'
|
- run: 'Get-Item ${{ matrix.volume.windows }}\2.h2w'
|
||||||
- run: 'Get-Item C:\3.h2w'
|
- run: 'Get-Item ${{ matrix.volume.windows }}\3.h2w'
|
||||||
- run: 'Get-Item C:\4.h2w'
|
- run: 'Get-Item ${{ matrix.volume.windows }}\4.h2w'
|
||||||
|
|
||||||
- run: '& .\f3read.exe -V'
|
- run: '& .\f3read.exe -V'
|
||||||
- run: '& .\f3read.exe --help'
|
- run: '& .\f3read.exe --help'
|
||||||
- run: '& .\f3read.exe -s 2 -e 4 -r 50000 /cygdrive/c'
|
- run: '& .\f3read.exe -s 2 -e 4 -r 50000 ${{ matrix.volume.cygwin }}'
|
||||||
|
2
f3read.c
2
f3read.c
@ -438,6 +438,8 @@ int main(int argc, char **argv)
|
|||||||
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
||||||
print_header(stdout, "read");
|
print_header(stdout, "read");
|
||||||
|
|
||||||
|
adjust_dev_path(&args.dev_path);
|
||||||
|
|
||||||
files = ls_my_files(args.dev_path, args.start_at, args.end_at);
|
files = ls_my_files(args.dev_path, args.start_at, args.end_at);
|
||||||
|
|
||||||
iterate_files(args.dev_path, files, args.start_at, args.end_at,
|
iterate_files(args.dev_path, files, args.start_at, args.end_at,
|
||||||
|
@ -372,6 +372,8 @@ int main(int argc, char **argv)
|
|||||||
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
argp_parse(&argp, argc, argv, 0, NULL, &args);
|
||||||
print_header(stdout, "write");
|
print_header(stdout, "write");
|
||||||
|
|
||||||
|
adjust_dev_path(&args.dev_path);
|
||||||
|
|
||||||
unlink_old_files(args.dev_path, args.start_at, args.end_at);
|
unlink_old_files(args.dev_path, args.start_at, args.end_at);
|
||||||
|
|
||||||
return fill_fs(args.dev_path, args.start_at, args.end_at,
|
return fill_fs(args.dev_path, args.start_at, args.end_at,
|
||||||
|
18
utils.c
18
utils.c
@ -18,10 +18,26 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
void adjust_dev_path(const char **dev_path)
|
||||||
|
{
|
||||||
|
if (chdir(*dev_path)) {
|
||||||
|
err(errno, "Can't change working directory to %s at %s()", *dev_path, __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chroot(*dev_path)) {
|
||||||
|
assert(!chdir("/"));
|
||||||
|
} else if (errno != EPERM) {
|
||||||
|
err(errno, "Can't change root directory to %s at %s()", *dev_path, __func__);
|
||||||
|
}
|
||||||
|
|
||||||
|
*dev_path = ".";
|
||||||
|
}
|
||||||
|
|
||||||
const char *adjust_unit(double *ptr_bytes)
|
const char *adjust_unit(double *ptr_bytes)
|
||||||
{
|
{
|
||||||
const char *units[] = { "Byte", "KB", "MB", "GB", "TB", "PB", "EB" };
|
const char *units[] = { "Byte", "KB", "MB", "GB", "TB", "PB", "EB" };
|
||||||
@ -216,8 +232,6 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice)
|
|||||||
|
|
||||||
#if (__APPLE__ && __MACH__) || defined(__OpenBSD__)
|
#if (__APPLE__ && __MACH__) || defined(__OpenBSD__)
|
||||||
|
|
||||||
#include <unistd.h> /* For usleep(). */
|
|
||||||
|
|
||||||
void msleep(double wait_ms)
|
void msleep(double wait_ms)
|
||||||
{
|
{
|
||||||
assert(!usleep(wait_ms * 1000));
|
assert(!usleep(wait_ms * 1000));
|
||||||
|
2
utils.h
2
utils.h
@ -9,6 +9,8 @@
|
|||||||
#define SECTOR_SIZE (512)
|
#define SECTOR_SIZE (512)
|
||||||
#define GIGABYTES (1024 * 1024 * 1024)
|
#define GIGABYTES (1024 * 1024 * 1024)
|
||||||
|
|
||||||
|
void adjust_dev_path(const char **dev_path);
|
||||||
|
|
||||||
const char *adjust_unit(double *ptr_bytes);
|
const char *adjust_unit(double *ptr_bytes);
|
||||||
|
|
||||||
/* Return true if @filename matches the regex /^[0-9]+\.h2w$/ */
|
/* Return true if @filename matches the regex /^[0-9]+\.h2w$/ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user