1 /* 2 * Copyright (c) 2015, 2018, 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 #if defined (__SUNPRO_C) && __SUNPRO_C >= 0x5140 30 #pragma error_messages(off, SEC_ARR_OUTSIDE_BOUND_READ) 31 #endif 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 JNIEXPORT jstring JNICALL Java_SEGVOverflow_nativesegv(JNIEnv *env, jobject obj) { 38 char *buffer1; 39 char *buffer2; 40 char *buffer3; 41 char ch; 42 43 jstring ret = NULL; 44 45 // sleep for a bit to let the libadimalloc library initialize 46 sleep(5); 47 48 // allocate three buffers 49 buffer1 = (char *)malloc(64); 50 buffer2 = (char *)malloc(64); 51 buffer3 = (char *)malloc(64); 52 if ((buffer1 == NULL) || (buffer2 == NULL) || (buffer3 == NULL)) { 53 // this return will result in a test failure 54 return ret; 55 } 56 57 // Read past the end of each buffer multiple times to increase the probability 58 // that an ADI version mismatch occurs so an ADI fault is triggered. 59 ch = buffer1[70]; 60 ch = buffer2[70]; 61 ch = buffer3[70]; 62 ch = buffer1[140]; 63 ch = buffer2[140]; 64 ch = buffer3[140]; 65 66 // create a failed test return value because this test should have cored 67 buffer1 = "TEST FAILED, a read past the end of a buffer succeeded."; 68 ret = (*env)->NewStringUTF(env, buffer1); 69 70 return ret; 71 } 72 73 #ifdef __cplusplus 74 } 75 #endif