~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
AC_ARG_ENABLE([gcc-vcheck],
[AS_HELP_STRING([--disable-gcc-vcheck], [do not check for buggy gcc version])],
gcc_check=$enableval, gcc_check="yes")

msg_gcc_check="use --disable-gcc-vcheck to disable this check. Before reporting any bugs check with a supported version of gcc"
VERSION_SUFFIX=
dnl Check for gcc-4.1.0
if test "$gcc_check" = "yes"; then
	if test "x$ac_compiler_gnu" = "xyes"; then
		AC_MSG_CHECKING([for a supported version of gcc])
		gcc_version=`${CC} -dumpversion`
		case "${gcc_version}" in
			4.1.0*)
				AC_MSG_RESULT([no (${gcc_version})])
				AC_MSG_ERROR([gcc 4.1.0 is known to incorrectly compile upx.c. Upgrade your compiler to at least 4.1.1/4.1.2)])
				;;
			*)
				AC_MSG_RESULT([ok (${gcc_version})])
				;;
		esac
		case "${gcc_version}" in
		    [[56789]].* | 4.[[3456789]].*)
			# bb #1581 - temporarely add -fno-strict-aliasing so gcc 4.4.0
			# works correctly
			CFLAGS="$CFLAGS -fno-strict-aliasing"
			;;
		    *)
			;;
		esac
	fi
else
	CFLAGS="$CFLAGS -O0"
	VERSION_SUFFIX="$VERSION_SUFFIX-broken-compiler"
fi

# add distcheck warning flags
distcheck_enable_flags=0
if test "x$ac_compiler_gnu" = "xyes"; then
	gcc_version=`${CC} -dumpversion`
	case "${gcc_version}" in
		4.[[3456789]]*)
			distcheck_enable_flags=1
			;;
		[[56789]].*)
			distcheck_enable_flags=1
			;;
	esac
fi

dnl Checks if compiler produces valid code, regardless of compiler
dnl we do these checks here to avoid receiving endless bugreports about
dnl breakages due to compiler bugs.

dnl Check if compiler produces invalid code on gcc PR27603 (affects upx.c)
dnl testcase from gcc testsuite
AC_MSG_CHECKING([for gcc bug PR27603])
AC_TRY_RUN(
	   [
/* (C) Richard Guenther */	   
void exit (int);
void abort (void);
int a;
int main(void)
{
  int j;
  for (j = 0; j < 6; j++)
  {
    if ((unsigned)j - 3 <= 1)
      exit (0);
    a = 1000 * (6 - j);
  }
  abort ();
}
], [AC_MSG_RESULT([ok, bug not present])],
[AC_MSG_ERROR([your compiler has gcc PR27603 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27603])], [AC_MSG_RESULT([cross-compiling, assumed ok])])

dnl Check if compiler produces invalid code on gcc PR26763-2 (affects upx.c)
dnl testcase from gcc testsuite
AC_MSG_CHECKING([for gcc bug PR26763-2])
AC_TRY_RUN(
	   [
/* (C) Richard Guenther */	   
extern void abort(void);

static int try (char *a, int d)
{
  return a + d > a;
}

int main(void)
{
  char bla[100];

  if (try (bla + 50, -1))
    abort ();

  return 0;
}
], [AC_MSG_RESULT([ok, bug not present])],
[AC_MSG_ERROR([your compiler has gcc PR26763-2 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26763])],[AC_MSG_RESULT([cross-compiling, assumed ok])])

dnl Check if compiler produces invalid code on own testcase based on upx.c
AC_MSG_CHECKING([for valid code generation of CLI_ISCONTAINED])
AC_TRY_RUN(
	   [
#include <stdio.h>
static struct v{
	char* dst;
	unsigned int dsize;
	unsigned int dcur;
	unsigned int backsize;
	signed int unp_offset;
} values[] = {
	{(char*)0xf78ab008, 0x2e000, 1, 4, -1594},
	{(char*)0xb7af1008, 0x2e000, 1, 4, -1594}

};
extern void abort(void);

#define CLI_ISCONTAINED(bb, bb_size, sb, sb_size)	\
  ((bb_size) > 0 && (sb_size) > 0 && (size_t)(sb_size) <= (size_t)(bb_size) \
   && (sb) >= (bb) && ((sb) + (sb_size)) <= ((bb) + (bb_size)) && ((sb) + (sb_size)) > (bb) && (sb) < ((bb) + (bb_size)))

int crashtest()
{
	unsigned int backsize, dcur;
	int dval=0x12000, unp_offset;
	int* dsize = &dval;
	char* dst = (char*)0x12000;
	while(1) {
		backsize=4;
		dcur=0;
		unp_offset=0x800002c7;

		if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0)
			return -1;
		abort();
	}
	return 0;
}

int main(void)
{
	int i;
	for(i=0;i<sizeof(values)/sizeof(values[0]);i++) {
		struct v* v= &values[i];
		char* dst = v->dst;
		unsigned int* dsize = &v->dsize;
		unsigned int dcur = v->dcur;
		unsigned int backsize = v->backsize-1;
		signed int  unp_offset = v->unp_offset;

		if(!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) ||
				!CLI_ISCONTAINED(dst, *dsize,dst+dcur,backsize) || unp_offset >= 0)  {
			continue;
		}
		abort();
	}
	crashtest();
	return 0;
}
], [AC_MSG_RESULT([ok, bug not present])],
[AC_MSG_ERROR([your compiler has a bug that causes clamav bug no. 670, use a different compiler, see http://bugs.clamav.net/bugzilla/show_bug.cgi?id=670])], [AC_MSG_RESULT([cross-compiling, assumed ok])])

dnl Check if compiler produces invalid code on gcc PR28045 (affects upx.c)
dnl testcase from gcc testsuite
AC_MSG_CHECKING([for gcc bug PR28045])
AC_TRY_RUN(
	   [
/* (C) Andrew Pinski */
extern void abort(void);
struct a
{
   unsigned int bits : 1;
   signed long val : ((sizeof(long) * 8) - 1);
};
static int Fnegate (struct a b)
{
  if ((-((long)b.val)) <= ((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))
      && (-((long)b.val)) >= (-(((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))) - 1))
     return 0 ;
  abort ();
}
int main (void)
{
  struct a b = {1, 1};
  Fnegate (b);
  return 0;
}
], [AC_MSG_RESULT([ok, bug not present])],
[AC_MSG_ERROR([your compiler has gcc PR28045 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28045])], [AC_MSG_RESULT([cross-compiling, assumed ok])])

dnl Check if compiler produces invalid code on gcc PR37573 (affects autoit.c)
dnl this is a bug in gcc 4.4.0, but for some reason it affects gcc 4.1.2 too
dnl gcc 4.1.3 is OK. This bug occurs only at -O3.
AC_MSG_CHECKING([for gcc bug PR37573])
AC_TRY_RUN(
	   [
#include <stdlib.h>
#include <string.h>
struct S
{
  unsigned int *a;
  unsigned int b;
  unsigned int c[624];
};
static unsigned char
foo (struct S *s)
{
  unsigned int r;
  if (!--s->b)
    {
      unsigned int *c = s->c;
      unsigned int i;
      s->a = c;
      for (i = 0; i < 227; i++)
	c[i] =
	  ((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
	  ((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i + 397];
      for (; i < 623; i++)
	c[i] =
	  ((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
	  ((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i - 227];
      c[623] =
	((((c[623] ^ c[0]) & 0x7ffffffe) ^ c[623]) >> 1) ^ ((0 - (c[0] & 1)) &
							    0x9908b0df) ^ c[i
									    -
									    227];
    }
  r = *(s->a++);
  r ^= (r >> 11);
  r ^= ((r & 0xff3a58ad) << 7);
  r ^= ((r & 0xffffdf8c) << 15);
  r ^= (r >> 18);
  return (unsigned char) (r >> 1);
}

void
bar (unsigned char *p, unsigned int q, unsigned int r)
{
  struct S s;
  unsigned int i;
  unsigned int *c = s.c;
  *c = r;
  for (i = 1; i < 624; i++)
    c[i] = i + 0x6c078965 * ((c[i - 1] >> 30) ^ c[i - 1]);
  s.b = 1;
  while (q--)
    *p++ ^= foo (&s);
};

static unsigned char p[23] = {
  0xc0, 0x49, 0x17, 0x32, 0x62, 0x1e, 0x2e, 0xd5, 0x4c, 0x19, 0x28, 0x49,
    0x91, 0xe4, 0x72, 0x83, 0x91, 0x3d, 0x93, 0x83, 0xb3, 0x61, 0x38
};

static unsigned char q[23] = {
  0x3e, 0x41, 0x55, 0x54, 0x4f, 0x49, 0x54, 0x20, 0x55, 0x4e, 0x49, 0x43,
    0x4f, 0x44, 0x45, 0x20, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x3c
};

int
main (void)
{
  unsigned int s;
  s = 23;
  bar (p, s, s + 0xa25e);
  if (memcmp (p, q, s) != 0)
	abort ();
  return 0;
}

], [AC_MSG_RESULT([ok, bug not present])],
[AC_MSG_ERROR([your compiler has gcc PR37573 bug, use a lower optimization level (-O1 or -O2), see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37573])], [AC_MSG_RESULT([cross-compiling, assumed ok])])

# It's not fatal if gperf is missing
AM_MISSING_PROG(GPERF, gperf)
AC_SUBST(GPERF)

AC_TYPE_OFF_T
AC_COMPILE_CHECK_SIZEOF([short])
AC_COMPILE_CHECK_SIZEOF([int])
AC_COMPILE_CHECK_SIZEOF([long])
AC_COMPILE_CHECK_SIZEOF([long long])
AC_COMPILE_CHECK_SIZEOF([void *])