Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 699508 - repoman: linechecks: Mishandling of % characters from ebuilds
Summary: repoman: linechecks: Mishandling of % characters from ebuilds
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Repoman (show other bugs)
Hardware: All All
: Normal normal (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks:
 
Reported: 2019-11-07 05:35 UTC by Arfrever Frehtes Taifersar Arahesis
Modified: 2020-05-15 00:19 UTC (History)
0 users

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


Attachments
Patch (repoman.patch,14.05 KB, patch)
2019-11-09 03:52 UTC, Arfrever Frehtes Taifersar Arahesis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Arfrever Frehtes Taifersar Arahesis 2019-11-07 05:35:41 UTC
If some strings coming from ebuilds contain % character and are returned by linechecks (in repoman/lib/repoman/modules/linechecks directory), then repoman prints messages with corrupted strings or exceptions occur.


Example 1:
  dosym /lib/%%/a a

$ repoman full

RepoMan scours the neighborhood...
  ebuild.absdosym
    app-misc/test/test-0.ebuild: dosym '/lib/%/a'... could use relative path on line: 10

(Notice that %% from ebuild was corrupted into single % in repoman's message.)


Example 2:
  dosym /lib/%/a a

$ repoman full

RepoMan scours the neighborhood...
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.7/repoman", line 45, in <module>
    sys.exit(repoman_main(sys.argv[1:]))
  File "/usr/lib/python3.7/site-packages/repoman/main.py", line 122, in repoman_main
    scanner.scan_pkgs(can_force)
  File "/usr/lib/python3.7/site-packages/repoman/scanner.py", line 358, in scan_pkgs
    self._scan_ebuilds(ebuildlist, dynamic_data)
  File "/usr/lib/python3.7/site-packages/repoman/scanner.py", line 383, in _scan_ebuilds
    _continue = func(**self.set_func_kwargs(mod, dynamic_data))
  File "/usr/lib/python3.7/site-packages/repoman/modules/scan/ebuild/multicheck.py", line 47, in check
    for check_name, e in self.controller.run_checks(f, pkg):
  File "/usr/lib/python3.7/site-packages/repoman/modules/linechecks/controller.py", line 139, in run_checks
    yield lc.repoman_check_name, e % (num + 1)
ValueError: unsupported format character '/' (0x2f) at index 13


Example 3:
  dosym /lib/%s/a a

$ repoman full

RepoMan scours the neighborhood...
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.7/repoman", line 45, in <module>
    sys.exit(repoman_main(sys.argv[1:]))
  File "/usr/lib/python3.7/site-packages/repoman/main.py", line 122, in repoman_main
    scanner.scan_pkgs(can_force)
  File "/usr/lib/python3.7/site-packages/repoman/scanner.py", line 358, in scan_pkgs
    self._scan_ebuilds(ebuildlist, dynamic_data)
  File "/usr/lib/python3.7/site-packages/repoman/scanner.py", line 383, in _scan_ebuilds
    _continue = func(**self.set_func_kwargs(mod, dynamic_data))
  File "/usr/lib/python3.7/site-packages/repoman/modules/scan/ebuild/multicheck.py", line 47, in check
    for check_name, e in self.controller.run_checks(f, pkg):
  File "/usr/lib/python3.7/site-packages/repoman/modules/linechecks/controller.py", line 139, in run_checks
    yield lc.repoman_check_name, e % (num + 1)
TypeError: not enough arguments for format string


All problems are caused by 'e % (num + 1)' interpolation in repoman/lib/repoman/modules/linechecks/controller.py:LineCheckController.run_checks() function.

Maybe dosym is currently the only way to reproduce this problem.
A workaround specific to repoman/lib/repoman/modules/linechecks/do/dosym.py would be:
-  return "dosym '%s'... could use relative path" % (match.group(1), ) + " on line: %d"
+  return "dosym '%s'... could use relative path" % (match.group(1).replace("%", "%%"), ) + " on line: %d"
Comment 1 Larry the Git Cow gentoo-dev 2019-11-08 04:55:27 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=d156784fd7557e8f5ce8a6de5cd3a6a38a78e436

commit d156784fd7557e8f5ce8a6de5cd3a6a38a78e436
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2019-11-08 04:52:42 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2019-11-08 04:54:37 +0000

    repoman: fix unsafe string interpolation (bug 699508)
    
    Reported-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
    Bug: https://bugs.gentoo.org/699508
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 repoman/lib/repoman/modules/linechecks/controller.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 2 Larry the Git Cow gentoo-dev 2019-11-08 05:43:36 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=d8879e74458935919a4303f4fd1d2d24eb92e094

commit d8879e74458935919a4303f4fd1d2d24eb92e094
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2019-11-08 05:42:16 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2019-11-08 05:43:26 +0000

    Revert "repoman: fix unsafe string interpolation (bug 699508)"
    
    This reverts commit d156784fd7557e8f5ce8a6de5cd3a6a38a78e436.
    The 'on line: %d' string fails to match some messages.
    
    Reported-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
    Bug: https://bugs.gentoo.org/699508
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 repoman/lib/repoman/modules/linechecks/controller.py | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
Comment 3 Arfrever Frehtes Taifersar Arahesis 2019-11-09 03:52:13 UTC
Created attachment 595514 [details, diff]
Patch
Comment 4 Larry the Git Cow gentoo-dev 2019-11-09 04:21:03 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/portage.git/commit/?id=bb6a2ca9ccc8d3d6f7feb7c9ac6b6c2b40ce9d28

commit bb6a2ca9ccc8d3d6f7feb7c9ac6b6c2b40ce9d28
Author:     Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
AuthorDate: 2019-11-09 03:39:53 +0000
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2019-11-09 04:06:05 +0000

    repoman: Fix unsafe string interpolation.
    
    "on line: %d" etc. is no longer included in messages returned from individual checks.
    "line %d: " is now consistently added by controller directly after ebuild path
    and precedes specific message.
    
    Example:
       app-misc/test/test-0.ebuild: line 5: please migrate from 'games' (no replacement)
       app-misc/test/test-0.ebuild: line 5: please migrate from 'versionator' to 'eapi7-ver (built-in since EAPI 7)'
       app-misc/test/test-0.ebuild: line 10: Useless blank line
       app-misc/test/test-0.ebuild: line 20: 'econf' call should be moved to src_configure
    
    Bug: https://bugs.gentoo.org/699508
    Signed-off-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 repoman/cnf/linechecks/linechecks.yaml             | 46 +++++++++++-----------
 repoman/lib/repoman/modules/linechecks/base.py     |  5 +--
 .../lib/repoman/modules/linechecks/controller.py   | 12 ++++--
 .../modules/linechecks/deprecated/inherit.py       | 18 +++------
 repoman/lib/repoman/modules/linechecks/do/dosym.py |  2 +-
 .../lib/repoman/modules/linechecks/eapi/checks.py  | 10 ++---
 .../lib/repoman/modules/linechecks/emake/emake.py  |  2 +-
 .../lib/repoman/modules/linechecks/phases/phase.py |  4 +-
 .../repoman/modules/linechecks/portage/internal.py |  7 +---
 .../repoman/modules/linechecks/quotes/quoteda.py   |  2 +-
 .../repoman/modules/linechecks/useless/dodoc.py    |  2 +-
 .../repoman/modules/linechecks/whitespace/blank.py |  2 +-
 12 files changed, 53 insertions(+), 59 deletions(-)
Comment 5 Zac Medico gentoo-dev 2019-11-09 06:06:15 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2b90833cb908ee9a64c7293feadb16294ee5adff

commit 2b90833cb908ee9a64c7293feadb16294ee5adff
Author:     Zac Medico <zmedico@gentoo.org>
AuthorDate: 2019-11-08 21:58:22 -0800
Commit:     Zac Medico <zmedico@gentoo.org>
CommitDate: 2019-11-08 21:59:23 -0800

    app-portage/repoman: Bump to version 2.3.18
    
     #690786 Support metadata/layout.conf restrict-allowed
     #699514 Detect dosym absolute paths starting with ${D}, ${ED} etc.
     #699508 Fix unsafe string interpolation.
    
    Package-Manager: Portage-2.3.79, Repoman-2.3.18
    Signed-off-by: Zac Medico <zmedico@gentoo.org>

 app-portage/repoman/Manifest              |  1 +
 app-portage/repoman/repoman-2.3.18.ebuild | 63 +++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)