Merge branch 'PHP-8.2'

* PHP-8.2:
  Fix undefined behaviour in GENERATE_SEED()
  Fix undefined behaviour when writing 32-bit values in phar/tar.c
This commit is contained in:
Niels Dossche 2023-03-26 16:16:26 +02:00
commit 0b212ab5ab
2 changed files with 10 additions and 8 deletions

View file

@ -1240,13 +1240,15 @@ nostub:
return EOF;
}
#ifdef WORDS_BIGENDIAN
# define PHAR_SET_32(var, buffer) \
*(uint32_t *)(var) = (((((unsigned char*)&(buffer))[3]) << 24) \
| ((((unsigned char*)&(buffer))[2]) << 16) \
| ((((unsigned char*)&(buffer))[1]) << 8) \
| (((unsigned char*)&(buffer))[0]))
# define PHAR_SET_32(destination, source) do { \
uint32_t swapped = (((((unsigned char*)&(source))[3]) << 24) \
| ((((unsigned char*)&(source))[2]) << 16) \
| ((((unsigned char*)&(source))[1]) << 8) \
| (((unsigned char*)&(source))[0])); \
memcpy(destination, &swapped, 4); \
} while (0);
#else
# define PHAR_SET_32(var, buffer) *(uint32_t *)(var) = (uint32_t) (buffer)
# define PHAR_SET_32(destination, source) memcpy(destination, &source, 4)
#endif
PHAR_SET_32(sigbuf, phar->sig_flags);
PHAR_SET_32(sigbuf + 4, signature_length);

View file

@ -65,9 +65,9 @@ PHPAPI double php_combined_lcg(void);
(__n) = (__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
# ifdef PHP_WIN32
# define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
# define GENERATE_SEED() (((zend_long) ((zend_ulong) time(NULL) * (zend_ulong) GetCurrentProcessId())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
# else
# define GENERATE_SEED() (((zend_long) (time(0) * getpid())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
# define GENERATE_SEED() (((zend_long) ((zend_ulong) time(NULL) * (zend_ulong) getpid())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
# endif
# define PHP_MT_RAND_MAX ((zend_long) (0x7FFFFFFF)) /* (1<<31) - 1 */