comparison test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress001.cpp @ 53223:bd8c721954a4

8210242: vmTestbase/nsk/stress/jni/jnistress001.java crashes with EXCEPTION_ACCESS_VIOLATION on windows-x86 Summary: Non-NUL-terminated string was passed to %s - use %.*s to specify the actual length. Reviewed-by: lfoltan, hseigel
author dholmes
date Thu, 25 Oct 2018 19:12:39 -0400
parents 79dc492c00ab
children 52be2c714a2f
comparison
equal deleted inserted replaced
1:f1eb055faa62 2:366e22a2463f
64 jclass clazz; 64 jclass clazz;
65 jmethodID methodID; 65 jmethodID methodID;
66 66
67 env->MonitorEnter(jobj); CE 67 env->MonitorEnter(jobj); CE
68 if (!allocs) { 68 if (!allocs) {
69 element = (CHAR_ARRAY *)malloc(sizeof(CHAR_ARRAY)); 69 element = (CHAR_ARRAY *)c_malloc(env, sizeof(CHAR_ARRAY));
70 element->str = (const char **)malloc(nstr*sizeof(const char *)); 70 element->str = (const char **)c_malloc(env, nstr*sizeof(const char *));
71 element->checkstr = (char **)malloc(nstr*sizeof(char *)); 71 element->checkstr = (char **)c_malloc(env, nstr*sizeof(char *));
72 for (j=0;j<nstr;j++) 72 for (j=0;j<nstr;j++)
73 element->checkstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); 73 element->checkstr[j] = (char *)c_malloc(env, DIGESTLENGTH*sizeof(char));
74 } 74 }
75 for(j=0;j<DIGESTLENGTH;j++) { 75 for(j=0;j<DIGESTLENGTH;j++) {
76 digest[j]=0; 76 digest[j]=0;
77 } 77 }
78 element->str[allocs] = env->GetStringUTFChars(jstr,0); CE 78 element->str[allocs] = env->GetStringUTFChars(jstr,0); CE
146 unsigned char digest[DIGESTLENGTH]; 146 unsigned char digest[DIGESTLENGTH];
147 static int index=0; 147 static int index=0;
148 static long len=0; 148 static long len=0;
149 static unsigned int equal=1; 149 static unsigned int equal=1;
150 char *elem; 150 char *elem;
151 int elem_len = -1;
151 152
152 const char *clsName = "nsk/stress/jni/JNIter001"; 153 const char *clsName = "nsk/stress/jni/JNIter001";
153 const char *name="setpass"; 154 const char *name="setpass";
154 const char *sig="(Z)V"; 155 const char *sig="(Z)V";
155 const char *halt="halt"; 156 const char *halt="halt";
158 jclass clazz; 159 jclass clazz;
159 jmethodID methodID; 160 jmethodID methodID;
160 161
161 env->MonitorEnter(jobj); CE 162 env->MonitorEnter(jobj); CE
162 if (!index) { 163 if (!index) {
163 javachars = (JCHAR_ARRAY *)malloc(sizeof(JCHAR_ARRAY)); 164 javachars = (JCHAR_ARRAY *)c_malloc(env, sizeof(JCHAR_ARRAY));
164 javachars->str = (const jchar **)malloc(nstr*sizeof(const jchar *)); 165 javachars->str = (const jchar **)c_malloc(env, nstr*sizeof(const jchar *));
165 javachars->checkstr = (char **)malloc(nstr*sizeof(char *)); 166 javachars->checkstr = (char **)c_malloc(env, nstr*sizeof(char *));
166 javachars->size = (int *)malloc(nstr*sizeof(int)); 167 javachars->size = (int *)c_malloc(env, nstr*sizeof(int));
167 for (j=0;j<nstr;j++) 168 for (j=0;j<nstr;j++)
168 javachars->checkstr[j] = (char *)malloc(DIGESTLENGTH*sizeof(char)); 169 javachars->checkstr[j] = (char *)c_malloc(env, DIGESTLENGTH*sizeof(char));
169 } 170 }
170 for(j=0;j<DIGESTLENGTH;j++) { 171 for(j=0;j<DIGESTLENGTH;j++) {
171 digest[j]=0; 172 digest[j]=0;
172 } 173 }
173 javachars->str[index] = env->GetStringChars(jstr,0); CE 174 javachars->str[index] = env->GetStringChars(jstr,0); CE
174 javachars->size[index] = env->GetStringUTFLength(jstr); CE 175 javachars->size[index] = env->GetStringUTFLength(jstr); CE
175 len += javachars->size[index]; 176 elem_len = javachars->size[index];
176 elem = (char*) malloc(javachars->size[index]*sizeof(char)); 177 len += elem_len;
177 for (j=0; j < javachars->size[index]; j++) { 178 elem = (char*) c_malloc(env, elem_len*sizeof(char));
179 for (j=0; j < elem_len; j++) {
178 elem[j] = (char) javachars->str[index][j]; 180 elem[j] = (char) javachars->str[index][j];
179 } 181 }
182
180 //memcpy(digest, elem, javachars->size[index]); 183 //memcpy(digest, elem, javachars->size[index]);
181 for(j=0;j<javachars->size[index]; j++) { 184 for(j=0;j<elem_len; j++) {
182 digest[j % DIGESTLENGTH]+=elem[j]; 185 digest[j % DIGESTLENGTH]+=elem[j];
183 } 186 }
184 memcpy(javachars->checkstr[index++],digest,DIGESTLENGTH); 187 memcpy(javachars->checkstr[index++],digest,DIGESTLENGTH);
185 if (index%printperiod==0) { 188 if (index%printperiod==0) {
186 printf("Check string sum for thread %s is ",elem); 189 printf("Check string sum for thread %.*s is ", elem_len, elem);
187 for (j=0;j<DIGESTLENGTH;j++) 190 for (j=0;j<DIGESTLENGTH;j++)
188 printf("%02x", digest[j]); 191 printf("%02x", digest[j]);
189 printf("\n"); 192 printf("\n");
190 } 193 }
191 free(elem); 194 free(elem);
192 if (index==nstr) { 195 if (index==nstr) {
193 printf("JNI Unicode strings memory=%ld\n",len); 196 printf("JNI Unicode strings memory=%ld\n",len);
194 tmpstr=env->NewString(javachars->str[index-1],javachars->size[index-1]); CE 197 tmpstr=env->NewString(javachars->str[index-1],elem_len); CE
195 for (j=0; j<nstr; j++) { 198 for (j=0; j<nstr; j++) {
196 elem = (char*) malloc(javachars->size[j]*sizeof(char)); 199 elem = (char*) c_malloc(env, javachars->size[j]*sizeof(char));
197 for (i=0; i < javachars->size[j]; i++) { 200 for (i=0; i < javachars->size[j]; i++) {
198 elem[i] = (char) javachars->str[j][i]; 201 elem[i] = (char) javachars->str[j][i];
199 } 202 }
200 //memcpy(digest, elem, javachars->size[j]); 203 //memcpy(digest, elem, javachars->size[j]);
201 for(i=0;i<DIGESTLENGTH;i++) { 204 for(i=0;i<DIGESTLENGTH;i++) {
235 //methodID=env->GetStaticMethodID(clazz, halt, haltSig); CE 238 //methodID=env->GetStaticMethodID(clazz, halt, haltSig); CE
236 //env->CallStaticVoidMethod(clazz, methodID); CE 239 //env->CallStaticVoidMethod(clazz, methodID); CE
237 return(tmpstr); 240 return(tmpstr);
238 } 241 }
239 env->MonitorExit(jobj); CE 242 env->MonitorExit(jobj); CE
240 return(env->NewString(javachars->str[index-1],javachars->size[index-1])); 243 return(env->NewString(javachars->str[index-1],elem_len));
241 } 244 }
242 245
243 } 246 }