Command Execution & POSIX Escaping¶
Because root operations execute through /system/bin/su -c <command_string>, shell injection is a catastrophic risk if arguments contain whitespace, quotes, or control characters. fparted enforces centralized escaping and rigid typing.
🛡️ The Typed Command Pipeline¶
flowchart TD
UI[User Interface Action] -->|Creates| Op[StorageOperation Object]
Op -->|Validated By| Plan[Command Planner]
Plan -->|Produces| Cmds[List of PlannedCommand]
Cmds -->|User Confirms| Exec[Privileged Process Executor]
Exec -->|Resolves Binary| Reg[Manifest Registry]
Exec -->|Sanitizes Args| Esc[POSIX Single-Quote Sanitizer]
Esc -->|Executes via| Su[/system/bin/su -c '...']
Su -->|Structured Result| Res[ExitCode, Stdout, Stderr, Duration]
Res -->|Triggers| Scan[Device Rescan]
🔒 POSIX Single-Quote Sanitization¶
Arguments are never concatenated with simple space interpolation. The executor applies strict POSIX single-quote escaping:
String sanitizeArgument(String arg) {
if (arg.contains('\x00')) {
throw ArgumentError('NUL byte detected in argument');
}
// Replace every single quote with '\''
return "'${arg.replaceAll("'", r"'\''")}'";
}
Examples of Safe Handling¶
| Input String | Sanitized Shell Representation |
|---|---|
My USB Drive |
'My USB Drive' |
Don't Panic |
'Don'\''t Panic' |
$(rm -rf /) |
'$(rm -rf /)' (Treated as literal string, no shell expansion) |
/dev/block/sda1; reboot |
'/dev/block/sda1; reboot' (Semicolon enclosed, no command chaining) |
⚙️ Deterministic Execution Environment¶
Commands execute inside a sanitized shell environment to eliminate host variability:
| Variable | Value | Purpose |
|---|---|---|
PATH |
/data/data/vn.shadichy.parted/files/usr/bin:... |
Forces verified toolchain resolution |
HOME |
/data/data/vn.shadichy.parted/files/home |
Isolated home directory |
TMPDIR |
/data/data/vn.shadichy.parted/files/usr/tmp |
Safe scratch directory |
LC_ALL |
C |
Predictable, locale-invariant output from CLI tools |