Skip to content

Commit b76e8ae

Browse files
committed
Prevent direct access of magic usages
1 parent 5afb4b8 commit b76e8ae

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/base/oven.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191
-- now we can post process the projects for 'uses' entries and apply the
9292
-- corresponding 'usage' block to the project.
93-
oven.bakeUsages()
93+
oven.applyUsages()
9494
end
9595

9696
---
@@ -894,7 +894,7 @@
894894
-- Post-process the projects for 'uses' entries and apply the corresponding
895895
-- 'usage' block to the project.
896896
--
897-
function oven.bakeUsages()
897+
function oven.applyUsages()
898898
local function fetchConfigSetBlocks(cfg)
899899
return cfg._cfgset.blocks
900900
end
@@ -981,6 +981,11 @@
981981
local uses = {}
982982

983983
for _, use in ipairs(cfg.uses or {}) do
984+
if p.usage.isSpecialName(use) then
985+
-- Explicitly providing special names is not allowed
986+
p.error("Special names are not allowed in 'uses' list. Found '%s' requested in project '%s'", use, cfg.project.name)
987+
end
988+
984989
-- Find a usage block that matches the usage name
985990
local namematch = p.usage.findglobal(use)
986991
for i = 1, #namematch do

src/base/usage.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
end
3434

3535

36+
---
37+
-- Checks if a usage name is a magic name (PUBLIC, PRIVATE, INTERFACE)
38+
--
39+
-- @param name
40+
-- The name of the usage.
41+
-- @return
42+
-- True if the usage is a special usage.
43+
---
44+
45+
function usage.isSpecialName(name)
46+
return name == usage.PUBLIC or name == usage.PRIVATE or name == usage.INTERFACE
47+
end
48+
49+
3650
---
3751
-- Check if the usage has a magic name (PUBLIC, PRIVATE, INTERFACE)
3852
--
@@ -41,7 +55,7 @@
4155
-- @return
4256
-- True if the usage is a special usage.
4357
function usage.isSpecial(self)
44-
return self.name == usage.PUBLIC or self.name == usage.PRIVATE or self.name == usage.INTERFACE
58+
return usage.isSpecialName(self.name)
4559
end
4660

4761

0 commit comments

Comments
 (0)