|
1 /* |
|
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 #include <stdio.h> |
|
25 #include <stdlib.h> |
|
26 #include <string.h> |
|
27 #include <unistd.h> |
|
28 #include <jni.h> |
|
29 |
|
30 #ifdef __cplusplus |
|
31 extern "C" { |
|
32 #endif |
|
33 |
|
34 JNIEXPORT jstring JNICALL Java_SEGVOverflow_nativesegv(JNIEnv *env, jobject obj) { |
|
35 char *buffer1; |
|
36 char *buffer2; |
|
37 char *buffer3; |
|
38 char ch; |
|
39 |
|
40 jstring ret = NULL; |
|
41 |
|
42 // sleep for a bit to let the libadimalloc library initialize |
|
43 sleep(5); |
|
44 |
|
45 // allocate three buffers |
|
46 buffer1 = (char *)malloc(64); |
|
47 buffer2 = (char *)malloc(64); |
|
48 buffer3 = (char *)malloc(64); |
|
49 if ((buffer1 == NULL) || (buffer2 == NULL) || (buffer3 == NULL)) { |
|
50 // this return will result in a test failure |
|
51 return ret; |
|
52 } |
|
53 |
|
54 // Read past the end of each buffer multiple times to increase the probability |
|
55 // that an ADI version mismatch occurs so an ADI fault is triggered. |
|
56 ch = buffer1[70]; |
|
57 ch = buffer2[70]; |
|
58 ch = buffer3[70]; |
|
59 ch = buffer1[140]; |
|
60 ch = buffer2[140]; |
|
61 ch = buffer3[140]; |
|
62 |
|
63 // create a failed test return value because this test should have cored |
|
64 buffer1 = "TEST FAILED, a read past the end of a buffer succeeded."; |
|
65 ret = (*env)->NewStringUTF(env, buffer1); |
|
66 |
|
67 return ret; |
|
68 } |
|
69 |
|
70 #ifdef __cplusplus |
|
71 } |
|
72 #endif |