Browse code

Remove flush(stdout) in pkg/chrootarchive/diff_unix.go and improve error reporting of flush() to fix #21103 pkg/chrootarchive/diff_unix.go erroneously calls flush on stdout, which tries to read from stdout returning an error. This has been fixed by removing the call and by modifying flush to return errors and checking for these errors on calls to flush.

Signed-off-by: Amit Krishnan <krish.amit@gmail.com>

Amit Krishnan authored on 2016/03/15 05:22:05
Showing 3 changed files
... ...
@@ -46,7 +46,10 @@ func untar() {
46 46
 		fatal(err)
47 47
 	}
48 48
 	// fully consume stdin in case it is zero padded
49
-	flush(os.Stdin)
49
+	if _, err := flush(os.Stdin); err != nil {
50
+		fatal(err)
51
+	}
52
+
50 53
 	os.Exit(0)
51 54
 }
52 55
 
... ...
@@ -65,8 +65,10 @@ func applyLayer() {
65 65
 		fatal(fmt.Errorf("unable to encode layerSize JSON: %s", err))
66 66
 	}
67 67
 
68
-	flush(os.Stdout)
69
-	flush(os.Stdin)
68
+	if _, err := flush(os.Stdin); err != nil {
69
+		fatal(err)
70
+	}
71
+
70 72
 	os.Exit(0)
71 73
 }
72 74
 
... ...
@@ -23,6 +23,6 @@ func fatal(err error) {
23 23
 
24 24
 // flush consumes all the bytes from the reader discarding
25 25
 // any errors
26
-func flush(r io.Reader) {
27
-	io.Copy(ioutil.Discard, r)
26
+func flush(r io.Reader) (bytes int64, err error) {
27
+	return io.Copy(ioutil.Discard, r)
28 28
 }