Skip to content

[Bug]: Potential null reference exception #4902

@tysonstrange

Description

@tysonstrange

By submitting this bug issue, you agree to the following.

  • This is a bug in the software that resides in this repository, and not a support matter (use https://otland.net/forums/support.16/ for support)
  • This issue is reproducible without changes to the C++ code in this repository
  • This bug has not been resolved in master branch
  • There is no existing issue for this bug already

Does this bug crash tfs?

yes

Server Version

1.7 (Master)

Operation System

all (listed below)

OS Description

No response

Bug description

Possible getConnection() null reference exception

Possible Pull Requests which are to blame

Steps to reproduce

  1. Compile
  2. Login
  3. Pray

Actual Behavior

Works for the most part, rare race condition could result in a null reference exception and crash the server.

void ProtocolLogin::onRecvFirstMessage(NetworkMessage& msg) checks if the connection exists auto connection = getConnection(); and then schedules a Task for getCharacterList()

PR #4709 for the HTTP Login server adds reference to getConnection()->getIP().to_string() without first checking if getConnection() returns a valid ptr

This line here:

db.escapeString(getConnection()->getIP().to_string())))) {

Just like in onRecvFirstMessage(), if it's going to reference it, it should check again since the function is scheduled to run later, even if it's within nano seconds.

Expected Behavior

If you're going to use/reference the connection, make sure it exists first like it does from ProtocolLogin::onRecvFirstMessage

auto connection = getConnection();
	if (!connection) {
		return;
	}

https://github.com/otland/forgottenserver/blob/master/src/protocollogin.cpp#L236

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue describing unexpected behavior of codeneeds-confirmationnot confirmed by a developer yet

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions