Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 843779 - Exceptions for reserved function and variable names
Summary: Exceptions for reserved function and variable names
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: PMS/EAPI (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: PMS/EAPI
URL: https://projects.gentoo.org/pms/8/pms...
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: 843680
  Show dependency tree
 
Reported: 2022-05-11 11:56 UTC by Ulrich Müller
Modified: 2022-05-16 06:16 UTC (History)
2 users (show)

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


Attachments
pkg-mgr-commands.tex: Tighten the spec for reserved names (0001-pkg-mgr-commands.tex-Tighten-the-spec-for-reserved-n.patch,1.89 KB, patch)
2022-05-11 21:56 UTC, Ulrich Müller
Details | Diff
pkg-mgr-commands.tex: Tighten the spec for reserved names (0001-pkg-mgr-commands.tex-Tighten-the-spec-for-reserved-n.patch,1.73 KB, patch)
2022-05-12 07:06 UTC, Ulrich Müller
Details | Diff
pkg-mgr-commands.tex: Tighten the spec on ebuild as a reserved name (0002-pkg-mgr-commands.tex-Tighten-the-spec-on-ebuild-as-a.patch,1.02 KB, patch)
2022-05-12 07:06 UTC, Ulrich Müller
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ulrich Müller gentoo-dev 2022-05-11 11:56:19 UTC
The spec says in section 12.3.17 "Reserved commands and variables" (since 2008 for the words, "__" was added in 2012):

Except where documented otherwise, all functions and variables that contain any of the following strings (ignoring case) are reserved for package manager use and may not be used or relied upon by ebuilds:

   * __ (two underscores) at beginning of string
   * abort
   * dyn
   * ebuild
   * hook
   * paludis
   * portage
   * prep


Related discussion in #gentoo-qa:

<+willikins> https://bugs.gentoo.org/843680 "[Tracker] Eclasses using reserved function and variable names"; Gentoo Linux, Eclasses; CONF; ulm:qa
<+arthurzam> ulm: I don't want to argue, but I think blocking the word "rebuild" from function name, as it contains "ebuild" is surprising.
[...]
<@ulm> I don't know, should the policy say "ebuild" except if it's in the string "rebuild"?
<@ulm> not sure if I'd want to open this can of worms
<+arthurzam> I will leave this decision to the people who know it :)
<@ulm> https://www.thefreedictionary.com/words-containing-ebuild
<@ulm> rebuild would pretty much cover it, I don't think we need to care about "musclebuilding" or "castlebuilder" :)

So, the proposal would be to say something like "ebuild (except if part of the string rebuild)".

I've checked the portage, pkgcore and paludis git repos, and AFAICS neither of them uses shell functions or variables with "rebuild" in their name.
Comment 1 Ulrich Müller gentoo-dev 2022-05-11 21:24:37 UTC
AFAICS "abort", "dyn", and "prep" only occured at the beginning of Portage's function and variable names, so we could also tighten the spec for these.
Comment 2 Ulrich Müller gentoo-dev 2022-05-11 21:56:43 UTC
Created attachment 778178 [details, diff]
pkg-mgr-commands.tex: Tighten the spec for reserved names
Comment 3 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-05-12 06:36:48 UTC
(In reply to Ulrich Müller from comment #1)
> AFAICS "abort", "dyn", and "prep" only occured at the beginning of Portage's
> function and variable names, so we could also tighten the spec for these.

I would be in favor of this but not the "rebuild" exception (it's too specific).  Could you split the two?
Comment 4 Ulrich Müller gentoo-dev 2022-05-12 07:06:33 UTC
Created attachment 778202 [details, diff]
pkg-mgr-commands.tex: Tighten the spec for reserved names
Comment 5 Ulrich Müller gentoo-dev 2022-05-12 07:06:55 UTC
Created attachment 778205 [details, diff]
pkg-mgr-commands.tex: Tighten the spec on ebuild as a reserved name
Comment 6 Ulrich Müller gentoo-dev 2022-05-12 07:08:56 UTC
(In reply to Michał Górny from comment #3)
> I would be in favor of this but not the "rebuild" exception (it's too
> specific).  Could you split the two?

Sure, see attached patches.

I've also changed the wording to "\t{ebuild} (unless immediately preceded by another letter)" which is less specific and not used by Portage.
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2022-05-12 08:05:53 UTC
Yeah, that makes more sense.  I'd consider going even further, to the equivalent of "\bebuild\b" but that'd require checking historical Portage uses.
Comment 8 Ulrich Müller gentoo-dev 2022-05-12 08:45:03 UTC
(In reply to Michał Górny from comment #7)
> Yeah, that makes more sense.  I'd consider going even further, to the
> equivalent of "\bebuild\b" but that'd require checking historical Portage
> uses.

In practice, that won't make much of a difference.

IMHO looking only for a prefix is slightly more systematic, because it will also cover the "begin with" case of the preceding list. In other words, names beginning with "ebuild" are not allowed.
Comment 9 Arthur Zamarin archtester Gentoo Infrastructure gentoo-dev Security 2022-05-13 05:06:25 UTC
I have started the work for implementing a check for this issue in pkgcheck. I have a starting skeleton which works and managed to report all ulm's findings in the various bugs he opened. (I know the spec are currently changing in this bug, so I will just update the implementation when final spec committed).

I have another question: I see that this rule applies to function names and variable names. Does it also apply to ebuilds, and also to all variable names? (I just saw that ulm opened for eclass functions only, so just want to recheck).
Comment 10 Ulrich Müller gentoo-dev 2022-05-13 06:03:55 UTC
(In reply to Arthur Zamarin from comment #9)
> I have another question: I see that this rule applies to function names and
> variable names. Does it also apply to ebuilds, and also to all variable
> names?

Yes, this also applies to ebuilds.
Comment 11 Larry the Git Cow gentoo-dev 2022-05-16 06:15:11 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/pms.git/commit/?id=260e21bf65f67ad424e990306a7a4789b6b2f1de

commit 260e21bf65f67ad424e990306a7a4789b6b2f1de
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2022-05-11 21:55:40 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2022-05-14 07:29:57 +0000

    pkg-mgr-commands.tex: Tighten the spec for reserved names
    
    "abort", "dyn" and "prep" are only reserved at the beginning of a name.
    This appears to be their only (historical and recent) usage in Portage.
    
    "ebuild" is allowed as substring of words like "rebuild", which is
    somewhat common in names.
    
    Bug: https://bugs.gentoo.org/843779
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 pkg-mgr-commands.tex | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)