| 1 |
// Command convert implements a landlocked image converter. |
| 2 |
// |
| 3 |
// Usage: |
| 4 |
// ./convert < input.jpeg > output.png |
| 5 |
// |
| 6 |
// This is a basic command line utility that reads from stdin and |
| 7 |
// writes to stdout. It has no business opening any additional files, |
| 8 |
// so we forbid it with a Landlock policy. Security issues in media |
| 9 |
// parsing libraries should not let the attacker access the file |
| 10 |
// system. |
| 11 |
package main |
| 12 |
|
| 13 |
import ( |
| 14 |
"image" |
| 15 |
_ "image/gif" |
| 16 |
_ "image/jpeg" |
| 17 |
"image/png" |
| 18 |
"log" |
| 19 |
"os" |
| 20 |
|
| 21 |
"github.com/landlock-lsm/go-landlock/landlock" |
| 22 |
) |
| 23 |
|
| 24 |
func main() { |
| 25 |
if err := landlock.V9.BestEffort().Restrict(); err != nil { |
| 26 |
log.Fatal("Could not enable Landlock:", err) |
| 27 |
} |
| 28 |
|
| 29 |
imgData, _, err := image.Decode(os.Stdin) |
| 30 |
if err != nil { |
| 31 |
log.Fatal("Could not read input:", err) |
| 32 |
} |
| 33 |
|
| 34 |
if err := png.Encode(os.Stdout, imgData); err != nil { |
| 35 |
log.Fatal("Could not write output:", err) |
| 36 |
} |
| 37 |
} |