6

There are problem-solving sites like topcoder.com, SPOJ. I'd like for similar use-case (people send me C++ program files) to do some restrictions.

One of those is:

  • "is not allowed using in-line assembly"

How can I enforce such prohibition? Is there smarter way (like compiler flags? - but I haven't found any useful) than just searching phrases in source-code ?

I can restrict people to g++ or clang. Things are being done on Linux.

Grzegorz Wierzowiecki
  • 10,545
  • 9
  • 50
  • 88
  • Why do you want to do that? Restricting inline asm doesn't help much if you're worried about security. – servn Jan 14 '12 at 09:10
  • @servn Ok. But I am not only worried about security, but fair C/C++ competition. I would like to prevent people from using asm, just because we decided about such rule. I want to automatize process of such policy. I understand it's not full solution and there is need for more. Thanks for pointing it out. Maybe you have some more ideas ? If interested in security, please check out my other questions : [Security.SE](http://security.stackexchange.com/users/4077?tab=questions) – Grzegorz Wierzowiecki Jan 14 '12 at 11:57

2 Answers2

4

How about:

% gcc -Dasm=error -D__asm__=error
Alnitak
  • 334,560
  • 70
  • 407
  • 495
  • How does it work? I understand it makes macros with names: `asm`, `__asm__`. Is shadowing build-in keywords allowed? Can I do the same for prohibiting function calls (like "system()") ? Is it safe solution - no way to workaround it (hack) ? – Grzegorz Wierzowiecki Jan 13 '12 at 10:20
  • 1
    @GrzegorzWierzowiecki the preprocessor gets its hand on the code before the compiler, and has no knowledge of keywords, so yes, it can change them. It can be worked around - a simple `#undef asm` in the code would do it. That would be easy to find though. – Alnitak Jan 13 '12 at 10:25
  • Each time I look at [The International Obfuscated C Code Contest ](http://www.ioccc.org/) I am more and more afraid there are ways to obfuscate things, like `#undef asm`. – Grzegorz Wierzowiecki Jan 13 '12 at 10:45
  • 1
    @GrzegorzWierzowiecki yes, it's hard to use technology to enforce policy. There are _always_ ways around it. – Alnitak Jan 13 '12 at 10:50
  • According to answer, I haven't idea that I can shadow keywords with preprocessor. Thanks a lot - It gives new possibilities :). – Grzegorz Wierzowiecki Jan 13 '12 at 11:19
0

Looks like you're looking for the -fno-asm flag.

Although it looks like that just does asm rather than also doing __asm__ so maybe add on a -D__asm__=something_that_will_error.

Also look at -fno-gnu-keywords for turning off asm in C++.

mattjgalloway
  • 34,792
  • 12
  • 100
  • 110