Skip to content

Commit

Permalink
Fix GH-17330: SNMP::setSecurity segfaults when object had been closed.
Browse files Browse the repository at this point in the history
checking when the workflow needs to deal with an existing SNMP session.

close GH-17337
  • Loading branch information
devnexen committed Jan 5, 2025
1 parent ee2faaa commit cd44814
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ PHP NEWS
. Fixed bug GH-17153 (SimpleXML crash when using autovivification on
document). (nielsdos)

- SNMP:
. Fixed bug GH-17330 (SNMP::setSecurity segfault on closed session).
(David Carlier)

- Sockets:
. Fixed bug GH-16276 (socket_strerror overflow handling with INT_MIN).
(David Carlier / cmb)
Expand Down
4 changes: 4 additions & 0 deletions ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,10 @@ PHP_METHOD(SNMP, setSecurity)
zend_string *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL, *a7 = NULL;

snmp_object = Z_SNMP_P(object);
if (!snmp_object->session) {
zend_throw_error(NULL, "Invalid or uninitialized SNMP object");
RETURN_THROWS();
}

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|SSSSSS", &a1, &a2, &a3, &a4,&a5, &a6, &a7) == FAILURE) {
RETURN_THROWS();
Expand Down
18 changes: 18 additions & 0 deletions ext/snmp/tests/gh17330.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
SNMP::setSecurity() segfault when the object had been closed.
--EXTENSIONS--
snmp
--CREDITS--
YuanchengJiang
--FILE--
<?php
$session = new SNMP(SNMP::VERSION_2c, "localhost", 'timeout_community_432');
$session->close();
try {
$session->setSecurity('authPriv', 'MD5', '', 'AES', '');
} catch(Error $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Invalid or uninitialized SNMP object

2 comments on commit cd44814

@nielsdos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devnexen You put this in the wrong place in NEWS...

@devnexen
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed now, yes forgot to check the level I was that in the file ...

Please sign in to comment.