The system function


#1

(This topic was created by moving off topic messages from the Clash of Wars topic. If you want to discuss further on the system function, do it here please)


you know we have no way to prevent players from using system calls

Couldn’t you hook the system when starting the process, and the hook would stop the process/return an error ?


Clash Wars, mini Clash of Code tournament
#2

You can’t really change the code directly since there’s many ways to call system. You can also hide it in an encoded string. That’s not a solution.

And C++ is not the only case. Many languages have a system command like php, C, C#, ruby, perl, javascript … CG will not code a code modification for every languages.

A solution could be to empty the PATH environnement variable when our code is started and prevent our code to access any binary. But you have to make an exception for the Bash languages or you’ll break every Bash codes on CG :smiley:

But if i remember well, CG already said that this is clearly not a priority. So we have to deal with it. Or, like me, abuse it :smiling_imp:


#4

For newcomers, i’ll talk about the system function in details:

In most languages, you have a system function. It can execute a system command line. For example in C++:

int main() {
    system("read n && echo n");
}

This code will read something from the standard input and print it on the standard output. In C++ it is easy since the system function is already plugged to standard input and output. In some other language like Java, you can’t do that easily since you have to spawn a process and pipe the standard input and output to the standard input and output of the child process.

So yes, if you already asked yourself: How is it possible to do a <50 characters C++ code in golf puzzle like Chuck Norris or Power of thor ? The solution is to use system and do it in bash. And most of the time, the bash code is a perl code like perl -lpe"insert your perl code here".

Is it an issue ? I don’t know. I personally abuse of it and i don’t really care. But i can understand that’s “unfair”. But like i said in my previous message, Codingame will probably not address this issue since it’s cleary not a priority.


#5

I see a lot of judging whether this or that “is a solution”. That doesn’t make sense (yet). You can’t discuss a solution before you’ve defined a problem, and nothing close to a general agreement has been found yet.

I see general complaints of “it’s unfair”, without ever really saying what “it” is.

Is “it” unfair that people who know more programming languages than others tend to win clashes? I wouldn’t see “solving” that as a world improvement. Knowledge is power, people who know more can do better, that’s a simple fact of life. That’s all the less unfair here that this knowledge is freely available to anyone who cares.

Is “it” unfair that it’s possible to mix up languages in a single [clash] solution? It would be if others were allowed to do it and not you, but that’s not the case. The argument is open. Any purity-based claim “it’s not True™ VB.NET anymore if you allow such or such” has a just-as-valid retort of “so, what?” There’s a reason people still write database in SQL instead of their locally-promoted imperative language. There’s a reason bash scripts call other programs. There’s a reason people don’t write their own SAT solver everytime they’re faced with a constraint propagation issue. Arguing for language-purity at all costs does not seem to me like a very reasonable point of view if you want to stick with everyday-life reason.

Sometimes it’s labelled as “cheating” instead.

To cheat involves breaking rules. There are very few written rules about clashes. Those that come to mind would be multi-account. Yes, I’d call cheating playing only clashes against sockpuppets to boost your rating. That’s about it for the CG rules.
Then we could extend to (most) national rules. Yes I’d call cheating DDOSing your clash opponents so they time out and you win. Or, heck, hiring a bounty hunter or SWATting them.

What’s left is ethics. Notoriously difficult to please all here.
Some people feel they abide by a certain set of unwritten rules, so everybody should abide by those too. Guess what: those same everybody would tend to disagree.
For example, I personally want to code stuff anew everytime I clash. Well, guess what, that’s just me! So I do hate it when my opponents solve a semi-hard clash in 10s because they had kept it from a previous time and just copy-pasted. All in all, there’s nothing I could do about: there is no written rule on the subject; there is next to nothing that can be implemented against it, so I’ll just have to deal with it. (by realizing clashing is broken by design and not partaking anymore)
Until those currently-unwritten rules effectively get written down, following them is merely a personal accomplishment: it’s likely worth all the bragging rights it deserves, yet nothing warrants enforcing them for all.

With that in mind…

Assuming you mean the system(3) function: mostly yes they could. But that solves neither the:

  • what about languages who bypass libc?
  • nothing prevents bypassing it anyway in libc-based languages
  • why should they anyway?

Any more generally/importantly: there’s even more ways to implement system.

What does that solve? It certainly doesn’t prevent calling anything that’s in the (now former) PATH.

How would you implement that?
It’s nefariously tricky to get this right with such pinpoint accuracy to a single process.

I’d tend to think Java is the only one in that case. The others have embraced Unix more organically. Any counterexample? C# perhaps?


TL;DR: the current system is fair. Some may dislike some or all aspects of it. It can (obviously) be changed, but be aware any vision of The perfect system is very unlikely to be shared by all.


#6

Welcome aboard :smiley:

As far as i know, it is possible to start a process on linux with an empty PATH and with a user who can’t access anything except the current folder (so /usr/bin is out of reach). But i would not recommend to do this for the actual Bash language (because it will obviously break Bash on all CG platform).

The previous javascript (SpiderMonkey) has a system function, but CG added a hack to disable it (for the temperature golf puzzle). Don’t know why javascript had a special treatment and not the other languages. But in NodeJS there’s no simple system function. It’s like java, you have to spawn a process (a lot of code) and pipe stdin and stdout to the new process (more code). There’s no way you’ll win a golf competition with this :smiley:


#7

That doesn’t make it any more the point.
It’s as easy as unset PATH; dosomething or your preferred variant. It’s still completely unrelated to access rights.
So why keep mentioning it?

Oh it’s certainly possible. It’s just painfully hard to get right. Here’s a random sampling of complications in general: libc access, other libraries’ access, the dynamic linker, languages’ runtime system dependencies. And a random sampling of CG-specific complications: maintaining I/O connectivity, maintaining buffering tweaks, maintaining temporary file capability, all that without creating a sterile environment that nobody could reproduce at home and complain about. While keeping it ptraced by gdb.

Each and every one of these hindrances has a workaround. That depends on the kernel version. And the distribution release. And the language interpreter used. And the language runtime used. And the language compiler used.

Special treatment? That is so UNFAIR !!!1!!


PS

Welcome aboard :smiley:

You’re a wee bit late to the party, lad! That was years ago.


#8

Wait wait wait … are you meaning that if you start a process on linux with a user without any rights except or the current folder (so, where the process is started), the process can still access something outside of this folder ? Last time i checked, most of linux distrib had a non-bugged user right system. I don’t see how any library can bypass the OS user right system.

EDIT: oh you mean that without any access, some languages can’t work. Well, maybe, i never checked every languages supported by CG. I’m pretty sure you can’t compile anything of course, but i just talked of running the process with a specific user.


#9

No.
I’m meaning if you start a process without any rights, you’ll have a hard time making it do anything at all.


#10

Yeah i corrected :smiley:


#11

TL;DR: the current system is fair. Some may dislike some or all aspects of it. It can (obviously) be changed, but be aware any vision of The perfect system is very unlikely to be shared by all.

I agree, these things are just a real feature of the languages. You can’t dislike features at will because in your head “that’s unfair”. For me perl is unfair in codegolf, just leave Java and C#.

If Codingame devels need to work on something, I’m sure they have plenty of stuff to do:

  • Leaderboards points. Current formula isn’t good enough.
  • Main page, with quests and stuff
  • Lag in leaderboards updates (>1min)
  • Maybe some tweaks to trueskill. Sometimes on low populated games played matches aren’t enough for a good placement.
  • I’d like to see Tensorflow/Keras/Caffe etc etc for inference, and some binary bigger size for ML inference. That’s much better than adding more esoteric languages that 0.0001% of the players used them.

#12

It’s impossible to one language be unfair or have advantage over any other language by design because we have separate leaderbords and points earned.

On the same reason using some language different from (or combined with) the one that selected in puzzle to be solved with is a natural cheating IMO. We have “Java” leaderboard, not “Java with Bash”, is this not enough?

I know that it’s not a priority for CG and that make me sad because the spirit of competition is somewhat disappearing.


#13

Since this topic was created because of an off topic discussion of Clash of Wars topic, i suppose Marchete was talking about CoC. Good luck with Java against Perl in a shortest CoC :smiley: