File: main.go

package info (click to toggle)
golang-github-landlock-lsm-go-landlock 0.0~git20250303.1544bcc-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 276 kB
  • sloc: makefile: 9
file content (37 lines) | stat: -rw-r--r-- 878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Command convert implements a landlocked image converter.
//
// Usage:
// ./convert < input.jpeg > output.png
//
// This is a basic command line utility that reads from stdin and
// writes to stdout. It has no business opening any additional files,
// so we forbid it with a Landlock policy. Security issues in media
// parsing libraries should not let the attacker access the file
// system.
package main

import (
	"image"
	_ "image/gif"
	_ "image/jpeg"
	"image/png"
	"log"
	"os"

	"github.com/landlock-lsm/go-landlock/landlock"
)

func main() {
	if err := landlock.V3.BestEffort().RestrictPaths(); err != nil {
		log.Fatal("Could not enable Landlock:", err)
	}

	imgData, _, err := image.Decode(os.Stdin)
	if err != nil {
		log.Fatal("Could not read input:", err)
	}

	if err := png.Encode(os.Stdout, imgData); err != nil {
		log.Fatal("Could not write output:", err)
	}
}