Skip to content

Move the check on the constant module/package flag to checkPool() - #14242

Merged
DanHeidinga merged 1 commit into
eclipse-openj9:masterfrom
ChengJin01:bcv_throw_cdnfe_for_module_class
Jan 11, 2022
Merged

Move the check on the constant module/package flag to checkPool()#14242
DanHeidinga merged 1 commit into
eclipse-openj9:masterfrom
ChengJin01:bcv_throw_cdnfe_for_module_class

Conversation

@ChengJin01

Copy link
Copy Markdown

The change is to move the check on the constant module/package
flag from readPool() to checkPool() to ensure a module class with
ACC_MODULE set is correctly captured/rejected as NoClassDefFoundError
prior to checkPool() during the static verification.

Internal ref 146836

Signed-off-by: Cheng Jin jincheng@ca.ibm.com

The change is to move the check on the constant module/package
flag from readPool() to checkPool() to ensure a module class with
ACC_MODULE set is correctly captured/rejected as NoClassDefFoundError
prior to checkPool() during the static verification.

Internal ref 146836

Signed-off-by: Cheng Jin <jincheng@ca.ibm.com>
@ChengJin01

ChengJin01 commented Jan 10, 2022

Copy link
Copy Markdown
Author

The existing code of checking CONSTANT_Module/CONSTANT_Package in readPool() is incorrect as the the access flags of the current class has not yet been determined until VM finishes traversing the constant pool (because the access flags of class file stay right after the constant pool). So the check (intended for classes without ACC_MODULE in the access flags) should be moved to checkPool() given the check on the access flags is done prior to checkPool() (invoked by checkClass()) in j9bcutil_readClassFileBytes():

/runtime/bcutil/cfreader.c

j9bcutil_readClassFileBytes(J9PortLibrary *portLib, ... )
{...
	if ((result = readPool(classfile, data, dataEnd, segment, segmentEnd, &index, &freePointer)) != 0) { <--------
		Trc_BCU_j9bcutil_readClassFileBytes_Exit(result);
		return result;
	}
	endOfConstantPool = index;
	VERBOSE_END(ParseClassFileConstantPool);

	CHECK_EOF(8);
	classfile->accessFlags = NEXT_U16(classfile->accessFlags, index); <------- accessFlags is set after readPool()

	/* class files with the ACC_MODULE flag set cannot be loaded */
	if (((flags & BCT_MajorClassFileVersionMask) >= BCT_JavaMajorVersionShifted(9))
		&& J9_ARE_ALL_BITS_SET(classfile->accessFlags, CFR_ACC_MODULE) <---- ACC_MODULE is check here
	) {
		errorCode = J9NLS_CFR_ERR_MODULE_IS_INVALID_CLASS__ID;
		errorAction = CFR_ThrowNoClassDefFoundError;
		offset = index - data - 2;
		goto _errorFound;
	}
...
	/* Structure verification. This is "Pass 1". */
	if (0 != (flags & CFR_StaticVerification)) {
---> if(checkClass(portLib, classfile, segment, (U_32) (endOfConstantPool - data), vmVersionShifted, flags)) {
			Trc_BCU_j9bcutil_readClassFileBytes_Exit(-1);
			return -1;
		}
	}
....

checkClass(J9PortLibrary *portLib, J9CfrClassFile* classfile, U_8* segment, U_32 endOfConstantPool, U_32 vmVersionShifted, U_32 flags)
{
...
	if(checkPool(classfile, segment, (U_8*)10, &maxBootstrapMethodIndex, flags)) { <-------
		return -1;
	}

@ChengJin01

Copy link
Copy Markdown
Author

Reviewer: @DanHeidinga
FYI: @gacholio, @tajila, @pshipton

@pshipton pshipton added this to the Release 0.31 (Java 18) milestone Jan 10, 2022

@DanHeidinga DanHeidinga left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks reasonable

@DanHeidinga

Copy link
Copy Markdown
Member

Jenkins test sanity zlinux jdk11,,jdk17

@DanHeidinga DanHeidinga self-assigned this Jan 10, 2022
@DanHeidinga
DanHeidinga merged commit 9bed0bf into eclipse-openj9:master Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants