Skip to content

When path is blank, is_resource_writable() will generate 'Uninitialized string offset: -1' #2820

Closed
@netniV

Description

@netniV

Describe the bug
If a blank path is passed to the is_resource_writable() function, this will cause PHP to generate a notice of Uninitialized string offset: -1 in /usr/share/cacti/site/lib/functions.php on line 5141

This was found during an upgrade from 1.2.3 to 1.2.5

Expected behavior
No notice should be given as is_resource_writable() should check for an empty string before attempting to manipulate it.

function is_resource_writable($path) {
        if ($path{strlen($path)-1}=='/') {
                return is_resource_writable($path.uniqid(mt_rand()).'.tmp');
        }

should be

function is_resource_writable($path) {
		if (empty($path)) {
			return false;
		}

        if ($path{strlen($path)-1}=='/') {
                return is_resource_writable($path.uniqid(mt_rand()).'.tmp');
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions