Azure / azure-sdk-for-php

Microsoft Azure SDK for PHP
http://azure.microsoft.com/en-us/develop/php/
Apache License 2.0
415 stars 273 forks source link

Fix Issue 984 (getGuid bug) #988

Closed mkasberg closed 5 years ago

mkasberg commented 6 years ago

This pull request fixes #984.

As identified by @znrk (#984), getGuid() is broken.

In fact, it's not only broken on the line identified for clock_seq_low, but also in 2 other places. mt_rand() is inclusive for both the max and the min, so mt_rand(0, 256) produces a max value of 0x100 rather than 0xff, overflowing from 2 bits to 3 bits. The fix is simple - changing the max value on the 3 lines where it's broken to ensure that the generated GUID is in line with the spec for version 4 (random GUID) at https://tools.ietf.org/html/rfc4122.

Note that I created a separate commit for the fix and for my tests. If you're opposed to merging my refactoring of getGuid(), I'm happy to create a pull request containing only the 3-line fix commit.

msftclas commented 6 years ago

CLA assistant check
All CLA requirements met.

captn3m0 commented 6 years ago

I've pushed a cleaner fix for this in https://github.com/Azure/azure-sdk-for-php/pull/991 (based on https://stackoverflow.com/a/15875555) that doesn't rely on mt_rand.

mkasberg commented 5 years ago

991 is a better fix, and has been merged.