Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 373073

Summary: cdrom.eclass: logic error in cdrom_get_cds path check
Product: Gentoo Linux Reporter: Jared B. <nitro>
Component: EclassesAssignee: Gentoo Games <games>
Severity: normal    
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---
Attachments: eutils.eclass.diff

Description Jared B. 2011-06-26 05:06:59 UTC
The cdrom_get_cds() function fails in such a way that seems to succeed even when a matching CD is not found when checking multiple CDs (such as to distinguish between an original or GotY version of a game).  If any given pattern matches the CD, it does correctly return that result; however, if no pattern matches, it will act as of the last pattern matched and continue processing the ebuild until a file operation fails because the correct files are not actually there.

I'm not sure how well I explained that, so an example will probably help.  Consider this pkg_setup() example:

cdrom_get_cds kingpin/
case ${CDROM_SET} in
	0) einfo "Found CD-ROM" ;;
	1) einfo "Found Existing Install" ;;
	*) die "unrecognized CD or installation source" ;;

As cdrom_get_cds is currently implemented, I get three possible results:

1. If CD_ROOT=cdrom, then 0 is returned
2. If CD_ROOT=install, then 1 is returned
3. If CD_ROOT=anything else, then 1 is returned

The die condition is never reached, because CDROM_SET gets set to 1 even on failure.  The problem is in this section beginning on line 1530:

einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
export CDROM_SET=-1
for f in ${CDROM_CHECK_1//:/ } ; do
	[[ -e ${CDROM_ROOT}/${f} ]] && break
export CDROM_MATCH=${f}

If $f never matches, CDROM_MATCH and CDROM_SET are set in the same way as if it did match the last option.  Notice also that the "Found CD ..." message is output even before the check is performed, which may lead to confusion if the correct CD is *not* actually found.

Here's a suggested fix:

export CDROM_SET=-1
for f in ${CDROM_CHECK_1//:/ } ; do
	if [[ -e ${CDROM_ROOT}/${f} ]]; then
		einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
		export CDROM_MATCH=${f}

This could probably be implemented a bit more elegantly, but the end result is that the CDROM_MATCH is only set, and the 'Found' message is only displayed, when an actual match is found.  Otherwise, a -1 is returned to indicate a failure.  With this fix in place, my pkg_setup() function behaves as expected and fails when an unrecognized CD is detected.

I'm attaching a small patch for the above change.

Reproducible: Always

Steps to Reproduce:
see description for example
Comment 1 Jared B. 2011-06-26 05:07:55 UTC
Created attachment 278183 [details, diff]
Comment 2 James Le Cuirot gentoo-dev 2017-04-05 20:48:57 UTC
This is a dupe but it's hopefully about to get fixed. Note that I'll make it die in the eclass instead. There's not much point in returning from a failed match as there's no way to recover from that situation.

*** This bug has been marked as a duplicate of bug 195868 ***