Skip to content

Buffer overflow in SingleRateThreeColorMeter.cc #1067

@dragos-bth

Description

@dragos-bth

There are actually two issues occurring in /inet/src/inet/networklayer/diffserv/SingleRateThreeColorMeter.cc. First, the use of deprecated sprintf() calls will be flagged as a problem by clang on MacOS Tahoe 26.1. Secondly, a statement such as sprintf(buf + strlen(buf), "rcvd: %d ", numRcvd);will attempt to write an int (I assume 4 bytes) past the end of buf.

Converting all three sprint() calls to snprintf(), such snprintf(buf, strlen(buf), "rcvd: %d ", numRcvd); should fix both problems.

void SingleRateThreeColorMeter::refreshDisplay() const
{
    char buf[80] = "";
    if (numRcvd > 0)
        sprintf(buf + strlen(buf), "rcvd: %d ", numRcvd);
    if (numYellow > 0)
        sprintf(buf + strlen(buf), "yellow:%d ", numYellow);
    if (numRed > 0)
        sprintf(buf + strlen(buf), "red:%d ", numRed);
    getDisplayString().setTagArg("t", 0, buf);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions