TSRM_API void *shmat(int key, const void *shmaddr, int flags)
{
shm_pair *shm = shm_get(key, NULL);
+ int err;
if (!shm->segment) {
return (void*)-1;
shm->addr = MapViewOfFileEx(shm->segment, FILE_MAP_ALL_ACCESS, 0, 0, 0, NULL);
+ err = GetLastError();
+ if (err) {
+ /* Catch more errors */
+ if (ERROR_NOT_ENOUGH_MEMORY == err) {
+ _set_errno(ENOMEM);
+ }
+ return (void*)-1;
+ }
+
return shm->addr;
}
--- /dev/null
+--TEST--
+Bug #72858 shm_attach null dereference
+--SKIPIF--
+<?php
+if (!extension_loaded("sysvshm")){ print 'skip'; }
+if (4 < PHP_INT_SIZE) { print "skip 32-bit only"; }
+if( substr(PHP_OS, 0, 3) != "WIN" ) { print "skip windows only" }
+?>
+--FILE--
+<?php
+
+$v1=100;
+$v2=0xffffffff / 4 + 0x1337;
+shm_attach($v1,$v2);
+
+?>
+==DONE==
+--EXPECTF--
+Warning: shm_attach(): failed for key 0x64: Not enough space in %s on line %d
+==DONE==