Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 373073 - cdrom.eclass: logic error in cdrom_get_cds path check
Summary: cdrom.eclass: logic error in cdrom_get_cds path check
Status: RESOLVED DUPLICATE of bug 195868
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Games
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-26 05:06 UTC by Jared B.
Modified: 2017-04-05 20:48 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
eutils.eclass.diff (eutils.eclass.diff,606 bytes, patch)
2011-06-26 05:07 UTC, Jared B.
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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/data1.cab:main/Pak0.pak
case ${CDROM_SET} in
	0) einfo "Found CD-ROM" ;;
	1) einfo "Found Existing Install" ;;
	*) die "unrecognized CD or installation source" ;;
esac

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
	((++CDROM_SET))
	[[ -e ${CDROM_ROOT}/${f} ]] && break
done
export CDROM_MATCH=${f}
return

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
	((++CDROM_SET))
	if [[ -e ${CDROM_ROOT}/${f} ]]; then
		einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
		export CDROM_MATCH=${f}
		return
	fi
done
CDROM_SET=-1
return

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]
eutils.eclass.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 ***