summaryrefslogtreecommitdiffstats
path: root/meta/recipes-multimedia/libtiff/files/001_support_patch_for_CVE-2020-35521_and_CVE-2020-35522.patch
blob: 9b4724a3252c7eba0498642953c7ca72091d8346 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
From 02875964eba5c4a2ea98c41562835428214adfe7 Mon Sep 17 00:00:00 2001
From: Thomas Bernard <miniupnp@free.fr>
Date: Sat, 7 Mar 2020 13:21:56 +0100
Subject: [PATCH] tiff2rgba: output usage to stdout when using -h

also uses std C EXIT_FAILURE / EXIT_SUCCESS
see #17

Signed-off-by: akash hadke <akash.hadke@kpit.com>
---
 tools/tiff2rgba.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)
---
Upstream-Status: Backport [https://gitlab.com/libtiff/libtiff/-/commit/02875964eba5c4a2ea98c41562835428214adfe7.patch]
---
diff --git a/tools/tiff2rgba.c b/tools/tiff2rgba.c
index 2eb6f6c4..ef643653 100644
--- a/tools/tiff2rgba.c
+++ b/tools/tiff2rgba.c
@@ -39,6 +39,13 @@
 #include "tiffiop.h"
 #include "tiffio.h"
 
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
 #define	streq(a,b)	(strcmp(a,b) == 0)
 #define	CopyField(tag, v) \
     if (TIFFGetField(in, tag, &v)) TIFFSetField(out, tag, v)
@@ -68,7 +75,7 @@ main(int argc, char* argv[])
 	extern char *optarg;
 #endif
 
-	while ((c = getopt(argc, argv, "c:r:t:bn8")) != -1)
+	while ((c = getopt(argc, argv, "c:r:t:bn8h")) != -1)
 		switch (c) {
 			case 'b':
 				process_by_block = 1;
@@ -86,7 +93,7 @@ main(int argc, char* argv[])
 				else if (streq(optarg, "zip"))
 					compression = COMPRESSION_DEFLATE;
 				else
-					usage(-1);
+					usage(EXIT_FAILURE);
 				break;
 
 			case 'r':
@@ -105,17 +112,20 @@ main(int argc, char* argv[])
 				bigtiff_output = 1;
 				break;
 
+			case 'h':
+				usage(EXIT_SUCCESS);
+				/*NOTREACHED*/
 			case '?':
-				usage(0);
+				usage(EXIT_FAILURE);
 				/*NOTREACHED*/
 		}
 
 	if (argc - optind < 2)
-		usage(-1);
+		usage(EXIT_FAILURE);
 
 	out = TIFFOpen(argv[argc-1], bigtiff_output?"w8":"w");
 	if (out == NULL)
-		return (-2);
+		return (EXIT_FAILURE);
 
 	for (; optind < argc-1; optind++) {
 		in = TIFFOpen(argv[optind], "r");
@@ -132,7 +142,7 @@ main(int argc, char* argv[])
 		}
 	}
 	(void) TIFFClose(out);
-	return (0);
+	return (EXIT_SUCCESS);
 }
 
 static int
@@ -166,7 +176,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
     if (tile_width != (rastersize / tile_height) / sizeof( uint32))
     {
 	TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
-	exit(-1);
+	exit(EXIT_FAILURE);
     }
     raster = (uint32*)_TIFFmalloc(rastersize);
     if (raster == 0) {
@@ -182,7 +192,7 @@ cvt_by_tile( TIFF *in, TIFF *out )
     if (tile_width != wrk_linesize / sizeof (uint32))
     {
         TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
-	exit(-1);
+	exit(EXIT_FAILURE);
     }
     wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
     if (!wrk_line) {
@@ -279,7 +289,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
     if (width != (rastersize / rowsperstrip) / sizeof( uint32))
     {
 	TIFFError(TIFFFileName(in), "Integer overflow when calculating raster buffer");
-	exit(-1);
+	exit(EXIT_FAILURE);
     }
     raster = (uint32*)_TIFFmalloc(rastersize);
     if (raster == 0) {
@@ -295,7 +305,7 @@ cvt_by_strip( TIFF *in, TIFF *out )
     if (width != wrk_linesize / sizeof (uint32))
     {
         TIFFError(TIFFFileName(in), "Integer overflow when calculating wrk_line buffer");
-	exit(-1);
+	exit(EXIT_FAILURE);
     }
     wrk_line = (uint32*)_TIFFmalloc(wrk_linesize);
     if (!wrk_line) {
@@ -528,7 +538,7 @@ tiffcvt(TIFF* in, TIFF* out)
             return( cvt_whole_image( in, out ) );
 }
 
-static char* stuff[] = {
+const static char* stuff[] = {
     "usage: tiff2rgba [-c comp] [-r rows] [-b] [-n] [-8] input... output",
     "where comp is one of the following compression algorithms:",
     " jpeg\t\tJPEG encoding",
@@ -547,13 +557,12 @@ static char* stuff[] = {
 static void
 usage(int code)
 {
-	char buf[BUFSIZ];
 	int i;
+	FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
 
-	setbuf(stderr, buf);
-        fprintf(stderr, "%s\n\n", TIFFGetVersion());
+        fprintf(out, "%s\n\n", TIFFGetVersion());
 	for (i = 0; stuff[i] != NULL; i++)
-		fprintf(stderr, "%s\n", stuff[i]);
+		fprintf(out, "%s\n", stuff[i]);
 	exit(code);
 }
 
-- 
GitLab