Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Issue 313 - Fully qualified names bypass private imports #5426

Merged
merged 7 commits into from
Feb 20, 2016

Conversation

MartinNowak
Copy link
Member

  • b/c we're using a global package tree, imported modules were
    accessible in other scopes using fully qualified names
  • maintain a whitelist of imported modules in the current scope

The implementation is a bit more complicated than I'd like it to be, mostly b/c of package modules (handling of which is spreaded accross many places), and the fact that a module can have a different name on the import side than in it's module declaration.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
313 [module] Fully qualified names bypass private imports

@MartinNowak
Copy link
Member Author

Seems like we need to reconsider the semantics of import pkg.mod : sym, b/c all the years this bug wasn't resolved it was possible in most places to do pkg.mod.sym, even though selective imports do not add the package.
OTOH changing the behavior now can break code b/c pkg could conflict w/ another local symbol.


/****************************************
* Check access to package/module p for scope sc.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need Ddoc style Params: section.

@MartinNowak
Copy link
Member Author

done

if (sc.scopesym && sc.scopesym.isPackageAccessible(p))
return false;
}
deprecation(loc, "%s %s is not accessible here", p.kind(), p.toPrettyChars());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append something like Perhaps add 'import %s;', as it's helpful to include corrective action as a hint to the user.

@MartinNowak
Copy link
Member Author

done

@ibuclaw
Copy link
Member

ibuclaw commented Feb 15, 2016

Why C++ headers, the only reason we still need C++ in the frontend and glue layer is that the other compilers haven't yet switched to D.

C++ will always be needed, whether or not we've switched to D is irrelevant.

@MartinNowak
Copy link
Member Author

C++ will always be needed, whether or not we've switched to D is irrelevant.

https://yourlogicalfallacyis.com/begging-the-question
Would be interesting to know why you need a C++ AST when the glue layer is ported to D.

@ibuclaw
Copy link
Member

ibuclaw commented Feb 15, 2016

Would be interesting to know why you need a C++ AST when the glue layer is ported to D.

Because porting the glue layer to D would require porting a lot of GCC to D.

@MartinNowak
Copy link
Member Author

Added a simple BitArray implementation.

@MartinNowak
Copy link
Member Author

Anything left?

@yebblies
Copy link
Member

LGTM. @WalterBright ?


~this()
{
mem.xfree(ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause multiple frees when copied. Could you e,g. disable postblit?


~BitArray()
{
mem.xfree(ptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this, too, is incorrect C++ code

@andralex
Copy link
Member

If we leave BitArray radioactive like this one day or another it'll ruin someone's day.

@MartinNowak
Copy link
Member Author

done

@MartinNowak
Copy link
Member Author

There is one aspect of this change I'm not 100% sure of. Should the fully qualified module name of a public import in an imported module be available?

module a;
import b;
void test()
{
  core.stdc.stdio.printf("");
  b.core.stdc.stdio.printf("");
}
module b;
public import core.stdc.stdio;
public static import core.stdc.stdlib; // or maybe a public static import

I stongly tend towards deprecating this as well, because it's relying on the exact imports in another module leaks implementation details. The purpose of public imports is to delegate functionality to another module, which module is that is should be the decision of the implementation as in this example.

version (UseA)
  public import drivers.a;
else
  public import drivers.b;

If reexporting a module is really wanted it's possible to add an explicit alias.

public import cstdio=core.stdc.stdio;
alias driver = drivers.a;

@andralex
Copy link
Member

Alrighty then. Let's cross the Rubicon!

@andralex
Copy link
Member

Auto-merge toggled on

andralex added a commit that referenced this pull request Feb 20, 2016
fix Issue 313 - Fully qualified names bypass private imports
@andralex andralex merged commit eb8c2c7 into dlang:master Feb 20, 2016
@MartinNowak MartinNowak deleted the fix313 branch February 20, 2016 16:53
MartinNowak added a commit to MartinNowak/dmd that referenced this pull request Mar 9, 2016
@MartinNowak
Copy link
Member Author

Great, I already spent 1-2 hour on the original BitArray implementation debugging a memory corruption b/c I mixed up number of words w/ number of bytes.
Now add another 3 hours to debug a memory corruption on Win64 found in an unrelated PR #5509.
Spending almost a whole working day instead of 5 minutes reusing a well tested data structure just b/c of some maybe-not-use-phobos formalities is of course an idiotic waste of time.
There are plenty of suboptimal data structures and algorithms left in dmd, we shouldn't repeat this exercise.

braddr added a commit that referenced this pull request Mar 9, 2016
fixup for #5426 - must clean newly reallocated bytes in BitArray
MartinNowak added a commit to MartinNowak/dmd that referenced this pull request Jul 24, 2016
- public imports in imported modules were not accessbile using their
  FQN, this was an oversight when adding the package tree masking to fix
  Bugzilla 313 (see dlang#5426)
- fixed by recursively checking imported scopes for accessible packages
- Uses the same reduced visibility distinction (only private vs. rest) as the
  unqualified symbol search, b/c extending importedScopes to track rich
  visibility (e.g. package(a.b)) was out of scope for a regression fix.
  This should be implemented when combining the search/import w/
  the symbol visibility mechanism.
MartinNowak added a commit to MartinNowak/dmd that referenced this pull request Jul 24, 2016
- public imports in imported modules were not accessbile using their
  FQN, this was an oversight when adding the package tree masking to fix
  Bugzilla 313 (see dlang#5426)
- fixed by recursively checking imported scopes for accessible packages
- Uses the same reduced visibility distinction (only private vs. rest) as the
  unqualified symbol search, b/c extending importedScopes to track rich
  visibility (e.g. package(a.b)) was out of scope for a regression fix.
  This should be implemented when combining the search/import w/
  the symbol visibility mechanism.
MartinNowak added a commit to MartinNowak/dmd that referenced this pull request Jul 29, 2016
- public imports in imported modules were not accessbile using their
  FQN, this was an oversight when adding the package tree masking to fix
  Bugzilla 313 (see dlang#5426)
- fixed by recursively checking imported scopes for accessible packages
- reuse Module.insearch to not follow import cycles
- Uses the same reduced visibility distinction (only private vs. rest) as the
  unqualified symbol search, b/c extending importedScopes to track rich
  visibility (e.g. package(a.b)) was out of scope for a regression fix.
  This should be implemented when combining the search/import w/
  the symbol visibility mechanism.
UplinkCoder pushed a commit to UplinkCoder/dmd that referenced this pull request Aug 31, 2016
- public imports in imported modules were not accessbile using their
  FQN, this was an oversight when adding the package tree masking to fix
  Bugzilla 313 (see dlang#5426)
- fixed by recursively checking imported scopes for accessible packages
- reuse Module.insearch to not follow import cycles
- Uses the same reduced visibility distinction (only private vs. rest) as the
  unqualified symbol search, b/c extending importedScopes to track rich
  visibility (e.g. package(a.b)) was out of scope for a regression fix.
  This should be implemented when combining the search/import w/
  the symbol visibility mechanism.
@CyberShadow
Copy link
Member

CyberShadow commented Dec 17, 2019

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=20453

Edit: this is already fixed on master.

@CyberShadow
Copy link
Member

This pull request introduced a regression:
https://issues.dlang.org/show_bug.cgi?id=20454

This variation is still present on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants