News for hackers. Stuff that matters.
Re:Evil Teacher: Code Injection in Moodle by dugmartin on Tuesday June 12, 2018 @03:11PM (#17296852)
I think the patch should have been to rip out eval() and build/use a shunting-yard parser/evaluator. A quick search found this: https://github.com/ircmaxell/php-math-parser

Leaving a call to eval() with user supplied input, no matter how well filtered, seems like way too big of a risk.

Re:Evil Teacher: Code Injection in Moodle by ihumanable on Tuesday June 12, 2018 @05:43PM (#17298331)
Agreed, when you are on patch #4 because the previous patches weren't effective, and you can't verify patch #4 because of time constraints, it might be time to step back and reconsider the approach.

Sounds like they should just not be eval()ing user input regardless of how much sanitization they throw at it.

Re:Evil Teacher: Code Injection in Moodle by userbinator on Tuesday June 12, 2018 @11:12PM (#17299950)
IMHO precedence climbing (a refactored version of recursive descent) would be much simpler and makes parsing seem almost trivial, since it can be made table-driven:

https://www.engr.mun.ca/~theo/Misc/exp_parsing.htm

Speaking of parsing simplicity and software design in general, you've coincidentally found a great example of how not to (ab)use OOP... one line of actual work wrapped in a dozen lines of boilerplate and replicated across multiple files with tiny variations:

https://github.com/ircmaxell/php-math-parser/tree/master/lib...

To put things into perspective, a precedence-climber for 13 levels of precedence from C's grammar, including a tokeniser, fits comfortably in <300 LoC of C, the bulk of that being the tokeniser. PHP's higher level nature (especially around string handling) would probably make a corresponding implementation even smaller.

Re:Evil Teacher: Code Injection in Moodle by sannee on Tuesday June 12, 2018 @08:46PM (#17299355)
Or use whatever tools are included in their language for safely evaluating strings (like ast.literal_eval in Python).
Re:Evil Teacher: Code Injection in Moodle by Something1234 on Tuesday June 12, 2018 @09:22PM (#17299524)
It's PHP there is none. In fact most languages don't include a safe way to evaluate strings out of the box.
Re:Evil Teacher: Code Injection in Moodle by jsjohnst on Tuesday June 12, 2018 @10:47PM (#17299860)
> It's PHP there is none.

This seems to disprove that, no?

https://secure.php.net/manual/en/runkit.sandbox.php

Re:Evil Teacher: Code Injection in Moodle by Something1234 on Tuesday June 12, 2018 @10:58PM (#17299896)
Allow me to rephrase, no cheap way to evaluate arbitrary strings without spinning up another vm.
Re:Evil Teacher: Code Injection in Moodle by jsjohnst on Tuesday June 12, 2018 @11:42PM (#17300065)
That’s not true either.
Re:Evil Teacher: Code Injection in Moodle by workinthehead on Wednesday June 13, 2018 @12:19AM (#17300215)
explain?
Re:Evil Teacher: Code Injection in Moodle by workinthehead on Wednesday June 13, 2018 @12:19AM (#17300214)
That's an extension. It doesn't come with PHP (not "out of the box").
Re:Evil Teacher: Code Injection in Moodle by jsjohnst on Wednesday June 13, 2018 @09:26AM (#17302802)
Rails doesn’t come with a default install of Ruby. Xcode doesn’t come pre-installed on macOS. You have to install Chrome on every major desktop OS as it doesn’t come by default.

Installing and configuring your environment to your needs should be entry level stuff for a developer, so what was the point of your reply?

[dead]
Re:Evil Teacher: Code Injection in Moodle by jsjohnst on Wednesday June 13, 2018 @11:02AM (#17303724)
> Can you explain why PHP developers are so uniquely unable to accept honest criticism of their language? Like, whence all the butthurt, bro?

I’m not a PHP developer. Nice try to deflect though! You obvious have an agenda you are trying to push at all costs and don’t want to learn, so have a great day!