Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8.1k
Promote warnings to exceptions in ext/shmop#5986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Uh oh!
There was an error while loading. Please reload this page.
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -149,8 +149,8 @@ PHP_FUNCTION(shmop_open) | ||
| } | ||
| if (flags_len != 1) { | ||
| php_error_docref(NULL, E_WARNING, "%s is not a valid flag", flags); | ||
| RETURN_FALSE; | ||
| zend_argument_value_error(2, "must be a valid access mode"); | ||
| RETURN_THROWS(); | ||
| } | ||
| object_init_ex(return_value, shmop_ce); | ||
| @@ -178,35 +178,35 @@ PHP_FUNCTION(shmop_open) | ||
| */ | ||
| break; | ||
| default: | ||
| php_error_docref(NULL, E_WARNING, "Invalid access mode"); | ||
| zend_argument_value_error(2, "must be a valid access mode"); | ||
| goto err; | ||
| } | ||
| if (shmop->shmflg & IPC_CREAT && shmop->size < 1) { | ||
| php_error_docref(NULL, E_WARNING, "Shared memory segment size must be greater than zero"); | ||
| zend_argument_value_error(4, "must be greater than 0 for the \"c\" and \"n\" access modes"); | ||
| goto err; | ||
| } | ||
| shmop->shmid = shmget(shmop->key, shmop->size, shmop->shmflg); | ||
| if (shmop->shmid == -1) { | ||
| php_error_docref(NULL, E_WARNING, "Unable to attach or create shared memory segment '%s'", strerror(errno)); | ||
| php_error_docref(NULL, E_WARNING, "Unable to attach or create shared memory segment \"%s\"", strerror(errno)); | ||
| goto err; | ||
| } | ||
| if (shmctl(shmop->shmid, IPC_STAT, &shm)) { | ||
| /* please do not add coverage here: the segment would be leaked and impossible to delete via php */ | ||
| php_error_docref(NULL, E_WARNING, "Unable to get shared memory segment information '%s'", strerror(errno)); | ||
| php_error_docref(NULL, E_WARNING, "Unable to get shared memory segment information \"%s\"", strerror(errno)); | ||
| goto err; | ||
| } | ||
| if (shm.shm_segsz > ZEND_LONG_MAX) { | ||
| php_error_docref(NULL, E_WARNING, "shared memory segment too large to attach"); | ||
| zend_argument_value_error(4, "is too large"); | ||
| goto err; | ||
| } | ||
| shmop->addr = shmat(shmop->shmid, 0, shmop->shmatflg); | ||
| if (shmop->addr == (char*) -1) { | ||
| php_error_docref(NULL, E_WARNING, "Unable to attach to shared memory segment '%s'", strerror(errno)); | ||
| php_error_docref(NULL, E_WARNING, "Unable to attach to shared memory segment \"%s\"", strerror(errno)); | ||
| goto err; | ||
| } | ||
| @@ -236,13 +236,13 @@ PHP_FUNCTION(shmop_read) | ||
| shmop = Z_SHMOP_P(shmid); | ||
| if (start < 0 || start > shmop->size) { | ||
| php_error_docref(NULL, E_WARNING, "Start is out of range"); | ||
| RETURN_FALSE; | ||
| zend_argument_value_error(2, "must be between 0 and the segment size"); | ||
kocsismate marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| RETURN_THROWS(); | ||
| } | ||
| if (count < 0 || start > (INT_MAX - count) || start + count > shmop->size) { | ||
| php_error_docref(NULL, E_WARNING, "Count is out of range"); | ||
| RETURN_FALSE; | ||
| zend_argument_value_error(3, "is out of range"); | ||
| RETURN_THROWS(); | ||
| } | ||
| startaddr = shmop->addr + start; | ||
| @@ -297,13 +297,13 @@ PHP_FUNCTION(shmop_write) | ||
| shmop = Z_SHMOP_P(shmid); | ||
| if ((shmop->shmatflg & SHM_RDONLY) == SHM_RDONLY) { | ||
| php_error_docref(NULL, E_WARNING, "Trying to write to a read only segment"); | ||
| RETURN_FALSE; | ||
| zend_throw_error(NULL, "Read-only segment cannot be written"); | ||
| RETURN_THROWS(); | ||
| } | ||
| if (offset < 0 || offset > shmop->size) { | ||
| php_error_docref(NULL, E_WARNING, "Offset out of range"); | ||
| RETURN_FALSE; | ||
| zend_argument_value_error(3, "is out of range"); | ||
| RETURN_THROWS(); | ||
| } | ||
| writesize = ((zend_long)ZSTR_LEN(data) < shmop->size - offset) ? (zend_long)ZSTR_LEN(data) : shmop->size - offset; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,57 +11,81 @@ edgarsandi - <edgar.r.sandi@gmail.com> | ||
| --FILE-- | ||
| <?php | ||
| echo PHP_EOL, '## shmop_open function tests ##'; | ||
| // warning outputs: invalid flag when the flags length != 1 | ||
| var_dump(shmop_open(1338, '', 0644, 1024)); | ||
| echo PHP_EOL, '## shmop_open function tests ##', PHP_EOL; | ||
| // warning outputs: invalid access mode | ||
| var_dump(shmop_open(1338, 'b', 0644, 1024)); | ||
| // Invalid flag when the flags length != 1 | ||
| try { | ||
| shmop_open(1338, '', 0644, 1024); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| // warning outputs: unable to attach or create shared memory segment | ||
| try { | ||
| shmop_open(1338, 'b', 0644, 1024); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| // Warning outputs: Unable to attach or create shared memory segment | ||
| var_dump(shmop_open(null, 'a', 0644, 1024)); | ||
| // warning outputs: Shared memory segment size must be greater than zero | ||
| var_dump(shmop_open(1338, "c", 0666, 0)); | ||
| // Shared memory segment size must be greater than zero | ||
| try { | ||
| shmop_open(null, 'a', 0644, 1024); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| //Shared memory segment size must be greater than zero | ||
| try { | ||
| shmop_open(1338, "c", 0666, 0); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| echo PHP_EOL, '## shmop_read function tests ##'; | ||
| // warning outputs: start is out of range | ||
| echo PHP_EOL, '## shmop_read function tests ##', PHP_EOL; | ||
| // Start is out of range | ||
| $shm_id = shmop_open(1338, 'n', 0600, 1024); | ||
| var_dump(shmop_read($shm_id, -10, 0)); | ||
| try { | ||
| shmop_read($shm_id, -10, 0); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| shmop_delete($shm_id); | ||
| // warning outputs: count is out of range | ||
| // Count is out of range | ||
| $shm_id = shmop_open(1339, 'n', 0600, 1024); | ||
| var_dump(shmop_read($shm_id, 0, -10)); | ||
| try { | ||
| shmop_read($shm_id, 0, -10); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| shmop_delete($shm_id); | ||
| echo PHP_EOL, '## shmop_write function tests ##'; | ||
| // warning outputs: offset out of range | ||
| echo PHP_EOL, '## shmop_write function tests ##', PHP_EOL; | ||
| // Offset out of range | ||
| $shm_id = shmop_open(1340, 'n', 0600, 1024); | ||
| var_dump(shmop_write($shm_id, 'text to try write', -10)); | ||
| try { | ||
| shmop_write($shm_id, 'text to try write', -10); | ||
| } catch (ValueError $exception) { | ||
| echo $exception->getMessage() . "\n"; | ||
| } | ||
| shmop_delete($shm_id); | ||
| ?> | ||
kocsismate marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| --EXPECTF-- | ||
| ## shmop_open function tests ## | ||
| Warning: shmop_open(): is not a valid flag in %s on line %d | ||
| bool(false) | ||
| Warning: shmop_open(): Invalid access mode in %s on line %d | ||
| bool(false) | ||
| shmop_open(): Argument #2 ($flags) must be a valid access mode | ||
| shmop_open(): Argument #2 ($flags) must be a valid access mode | ||
| Warning: shmop_open(): Unable to attach or create shared memory segment '%s' in %s on line %d | ||
| Warning: shmop_open(): Unable to attach or create shared memory segment "%s" in %s on line %d | ||
| bool(false) | ||
| Warning: shmop_open(): Shared memory segment size must be greater than zero in %s on line %d | ||
| bool(false) | ||
| Warning: shmop_open(): Unable to attach or create shared memory segment "%s" in %s on line %d | ||
| shmop_open(): Argument #4 ($size) must be greater than 0 for the "c" and "n" access modes | ||
| ## shmop_read function tests ## | ||
| Warning: shmop_read(): Start is out of range in %s on line %d | ||
| bool(false) | ||
| Warning: shmop_read(): Count is out of range in %s on line %d | ||
| bool(false) | ||
| shmop_read(): Argument #2 ($start) must be between 0 and the segment size | ||
| shmop_read(): Argument #3 ($count) is out of range | ||
| ## shmop_write function tests ## | ||
| Warning: shmop_write(): Offset out of range in %s on line %d | ||
| bool(false) | ||
| shmop_write(): Argument #3 ($offset) is out of range | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.