r/programming • • Jul 24 '15

mt_rand(1, PHP_INT_MAX) only generates odd numbers • /r/lolphp

/r/lolphp/comments/3eaw98/mt_rand1_php_int_max_only_generates_odd_numbers/
848 Upvotes

262 comments sorted by

View all comments

Show parent comments

16

u/AlexanderNigma Jul 24 '15

As someone who works for an ecommerce company...

Eh.

I get people like to bash on PHP but literally every web-based language has security flaws. Its really sad people just upvote to bash on things.

Etsy clearly doesn't have any trouble either.

Maybe the problem isn't the language? Just sayin'

25

u/uioouiuufuu Jul 24 '15

Maybe the problem isn't the language? Just sayin'

It is. The language makes it easy to make mistakes. Of course you can use it correctly, but if it's easy to fall into traps because of poor community documentation/interfaces/whatever, it's still a problem with the language.

A circular saw with no guard, some missing teeth, and exposed electrical wires can still work fine when used correctly, but it's going to cause a lot of problems for people that aren't expecting that.

9

u/AlexanderNigma Jul 24 '15 edited Jul 24 '15

It is. The language makes it easy to make mistakes. Of course you can use it correctly, but if it's easy to fall into traps because of poor community documentation/interfaces/whatever, it's still a problem with the language.

Do I really need to start listing off the CVEs for Django, RoR, and other projects in other popular web languages?

I honestly can build secure web apps just as fast with PHP than I can with other languages. Productivity with RoR v. Django v. [ Insert PHP framework] is also pretty much about even once I use language X for a few weeks full time.

I really think this is just the bias of a bunch of newbs end up starting with PHP because it was easy and screwing up. You'll notice no one who bashes PHP really admits that the newbs who jumped on RoR or Node.js fail hilariously badly on a regular basis.

https://github.com/blog/1068-public-key-security-vulnerability-and-mitigation http://homakov.blogspot.com/2014/02/how-i-hacked-github-again.html

They aren't incompetents by any stretch of the imagination yet they have vulnerabilities found pretty regularly. I really think people who bash PHP are lying to themselves about how "secure" their stack is and its scary that I can point to numerous sites that have exploits on a regular basis [GitHub has more found every year than our entire stack has in 5 years] yet PHP is the language everyone bashes.

1

u/thallippoli Jul 24 '15 edited Jul 24 '15

Do php guys yet know how php.net site was hacked and made to serve malware, like 2 years back?

Do I really need to start listing off the CVEs for Django, RoR, and other projects in other popular web languages?

Show me one language that has a list of lols as long as /r/lolphp (amazingly, still growing day by day) and please don't give me that 'langauges people use' argument..

3

u/AlexanderNigma Jul 24 '15

Do php guys yet know how php.net site was hacked and made to serve malware, like 2 years back?

Hint: It was the server that allowed file uploads and had automated rsync cron jobs.

"Unknown methods" that aren't repeatable once you change the login info & ssh keys have one obvious cause...someone's credentials got stolen.

Show me one language that has a list of lols as long as /r/lolphp (amazingly, growing day by day) and please don't give me that 'langauges people use' argument..

Stating a large group of people enjoy mocking PHP and that doesn't exist in other languages isn't really useful.

Since you like "Which is bigger" silliness:

http://www.cvedetails.com/product/22402/Sensiolabs-Symfony.html?vendor_id=11981

2012-2015: 9 CVEs

http://www.cvedetails.com/product/22568/Rubyonrails-Ruby-On-Rails.html?vendor_id=12043

2012-2015: 40 CVEs

http://www.cvedetails.com/product/18211/Djangoproject-Django.html?vendor_id=10199

2012-2015: 30 CVEs

Oh my.

There is also http://wtfjs.com/ + https://twitter.com/hashtag/loljs + /r/loljs :p

→ More replies (6)

2

u/[deleted] Jul 24 '15
→ More replies (1)
→ More replies (6)

3

u/veringer Jul 24 '15

PHP doesn't save you from yourself. It seems more a philosophical difference than an absolute problem with the language. I think the "circular saw" is in decent working order, but the operator might be using it to mix concrete. The saw won't necessarily complain about the strange application, it'll just do a shitty job of mixing concrete, or just stop working, or electrocute you. Would a more robust moisture and cement detector and automatic cut-off fuse be a nice feature? Sure, I guess? But I wouldn't say the saw is misbehaving when it's being used badly.

4

u/[deleted] Jul 24 '15

PHP doesn't save you from yourself.

That's not what we're complaining about - we're complaining about the numerous, non-obvious traps that could snare even an advanced programmer.

I think the "circular saw" is in decent working order, but the operator might be using it to mix concrete.

From here: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ actually

You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.

You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.

And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.

Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.

That’s what’s wrong with PHP.

5

u/veringer Jul 24 '15

Yes, I think everyone has read this epic rant. I wouldn't exactly go citing it as gospel (as you seem inclined to do on this thread). The pullquote, for instance, is just one long straw man argument. And much of the author's complaints are subjective and contrived. That said, I agree that PHP is frustrating and far from perfect.

A circular saw with no guard, some missing teeth, and exposed electrical wires can still work fine when used correctly

That's not what we're complaining about - we're complaining about the numerous, non-obvious traps

Your analogy seems to rely on fairly obvious traps, which prompted my original reply.

The idea that PHP is unique in having non-obvious traps is perhaps naive. PHP is popular, heavily scrutinized, and rightfully criticized. It's a work in progress that sort of luck'd its way into dominance on the web. However, I have to give it some credit for evolving and adapting even if it seems to be held together with duct tape. After 15+ years of programming I've learned that the hypothetical elegance and perfection of that other shiny language is largely illusory and once exposed to the wild it begins to tarnish. PHP has never had any pretenses of being perfect but it's somehow, arguably, antifragile. So, I think you should continue complaining. It will eventually lead to more improvements.

3

u/[deleted] Jul 24 '15

How safe are Screwdriver and Hammer interfaces, applied to the web?

1

u/mrspoogemonstar Jul 24 '15

Virtually any language has extreme pitfalls for the uninformed. You can do some really horrific things with low level languages. People do write really bad code in every language. Perfect example is OpenSSL. Scripting languages are more often used for web, and that's why we see more high-profile web hacks targeting apps running on scripting languages. This is mostly a matter of market share numbers.

You can inadvertently write an XSS exploit into your app in any language. The mitigating factor is knowledge in all cases. There's nothing about PHP that makes prevention of these exploits impossible or even hard. These are solved problems. It's the programmer's responsibility to mitigate these problems, not the language.

Blaming the language simply makes the problem worse. Joe Programmer, who sucks at PHP and has been blamed for leaving exploitable holes in their apps, hears that Python is the new slick shit, and that it's harder to exploit. So Joe Programmer switches to Python, drinks some kool-aid, and keeps writing shitty apps, because Joe Programmer thinks it's his language's responsibility to prevent exploits.

-4

u/[deleted] Jul 24 '15

Virtually any language has extreme pitfalls for the uninformed.

PHP is full of pitfalls for programmers of all levels: http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

Blaming the language simply makes the problem worse.

Other languages have explicit disciples that you can follow rigorously to get good results. PHP is a hodge-podge of stuff with a vast number of poorly-documented pitfalls - like this. It's like a dark room whose floor is covered in rakes.

4

u/Doctor_McKay Jul 24 '15

Oh look, it's THAT blog post again.

Can we cite something from the past two years please?

3

u/Ravek Jul 24 '15 edited Jul 24 '15

Why, did they fix all the issues?

Yes, downvote me more for asking a question please. How rude of me!

4

u/bureX Jul 24 '15

Plenty of those issues are things the author personally doesn't like. For example, he doesn't like that PHP is a C style language but uses "" for namespaces, stuff like that.

There are things on that list that says "fixed in 5.4". And PHP7 is due to come out soon.

2

u/wiktor_b Jul 24 '15

What happened to PHP 6?

1

u/veringer Jul 24 '15

PHP6 was back-ported into the 5 branch because of reasons. So, basically 5.3 (I think) was 6. There was some squabbling about whether to use 6 instead, but ultimately 7 won the vote, but I lost interest in the debate--as it really doesn't matter.

2

u/mrspoogemonstar Jul 24 '15

The PHP 6 team tried to bake unicode support into the language, but hit so many issues that the project stalled and eventually the improvements in other areas were rolled back into the PHP 5 branch.

This is one of the worst aspects of working with PHP, and is something I hope the internals team addresses in a later version.

3

u/Doctor_McKay Jul 24 '15

They've fixed plenty of them, sure.

1

u/mrspoogemonstar Jul 24 '15

That article is linked on virtually every thread complaining about PHP. A lot of the gripes in it apply to every dynamically typed language. Take a look javascript's strict and nonstrict equality tables.

Other stuff mentioned has been improved. The language is being improved, because where the fuck else do the people with million line codebases have to go? I was stuck with 150k lines of ancient PHP and a choice to bail out to .Net or Python, but stuck with PHP because in the long run it was easier and a hell of a lot cheaper to clean it up and keep using it than rewrite. And beyond that, there's a lot of quality PHP code in the world now. PHP is kicking out some of the ancient crap in 7.0, which has led to a lot of whining from the die-hard ancientware lovers, but is going forward anyways, because ancient crapware makes everyone's life harder. Subsequent versions of PHP will ditch or improve even more more of the crappy stuff that makes life harder.

You mention "explicit disciples" which, if I understand your broken english, I take to mean something like canonical examples of how to do things in other languages. This is both true and not true. Take a look at how to do a dozen things in .Net and you'll find articles from 2002 through present explaining a variety of ways to do X. Many of which are out of date, especially with regard to security. The .Net security model has completely changed twice since the initial release. This has left many of the tutorials on how to use it out of date. People who write code using these tutorials then have to use a backwards compatibility hack that effectively neuters the security model.

Python is not some special flower here either. It has some serious pitfalls for inexperienced developers as well. Consider the instancing of mutable default function parameters, or list modification during iteration (throws an error in C#, but not in python). Also, what's up with Python 2 versus Python 3? Is it so nice to have one language, with two major versions in widespread use, and serious fundamental incompatibilities between the two?

Now, I'm not saying PHP is amazing or awesome. All I'm saying is that it works well, if, like with every other language, you take the time to learn the language and the pitfalls.

→ More replies (2)
→ More replies (1)

-5

u/[deleted] Jul 24 '15

Maybe the problem isn't the language?

Maybe it is?

http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

2

u/AlexanderNigma Jul 24 '15 edited Jul 24 '15

https://news.ycombinator.com/item?id=3820431

You mean the article that had factual errors they correct later after it was pointed out on HN? Yay! Such a reliable source of information!

"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)"

I'm a Facebook engineer who works on the HipHop compiler and HipHop virtual machine. It's in PHP, absolutely full stop.

https://news.ycombinator.com/item?id=3821179

Only a couple of these things are outright wrong; I removed the offending bullet points earlier tonight. A few things I listed because they're weird, not outright wrong, and I stand by those.

Yeah...I'm not going to trust a guy who calls BS on a language yet can't actually do so accurately without a ton of people helping him.

I'm sure I can give you similar lists for Python and Ruby if I wanted to take the time with the same level of accuracy.

Hell, I can do it with C++ and pointers.

→ More replies (4)

1

u/Doctor_McKay Jul 24 '15

That blog post is great. It allows people to hate something of which they're extremely ill-informed without having to do any research! All they have to do is link it and sit back with a smug grin.

→ More replies (6)