Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Data/src/Row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ bool Row::operator < (const Row& other) const
if (_values[it->get<0>()].convert<double>() <
other._values[it->get<0>()].convert<double>())
return true;
// CodeQL [cpp/float-equality]: intentional exact comparison in dynamic type system
else if (_values[it->get<0>()].convert<double>() !=
other._values[it->get<0>()].convert<double>())
return false;
Expand Down
1 change: 0 additions & 1 deletion Data/src/SQLChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ void SQLChannel::run()
{
try
{
sleepTime = 100;
if (_reconnect)
{
close();
Expand Down
2 changes: 1 addition & 1 deletion Data/testsuite/src/Extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class Extractor: public Poco::Data::AbstractExtractor
bool extract(std::size_t pos, Poco::Nullable<UUID>& val) override;
/// Extracts a Nullable<UUID>.

bool isNull(std::size_t col, std::size_t row = -1) override;
bool isNull(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) override;
/// Returns true if the current row value at pos column is null.

void reset() override;
Expand Down
4 changes: 4 additions & 0 deletions Foundation/include/Poco/Dynamic/Var.h
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,7 @@ inline bool operator == (const float& other, const Var& da)
/// Equality operator for comparing Var with float
{
if (da.isEmpty()) return false;
// CodeQL [cpp/float-equality]: intentional exact comparison in dynamic type system
return other == da.convert<float>();
}

Expand All @@ -1866,6 +1867,7 @@ inline bool operator != (const float& other, const Var& da)
/// Inequality operator for comparing Var with float
{
if (da.isEmpty()) return true;
// CodeQL [cpp/float-equality]: intentional exact comparison in dynamic type system
return other != da.convert<float>();
}

Expand Down Expand Up @@ -1962,6 +1964,7 @@ inline bool operator == (const double& other, const Var& da)
/// Equality operator for comparing Var with double
{
if (da.isEmpty()) return false;
// CodeQL [cpp/float-equality]: intentional exact comparison in dynamic type system
return other == da.convert<double>();
}

Expand All @@ -1970,6 +1973,7 @@ inline bool operator != (const double& other, const Var& da)
/// Inequality operator for comparing Var with double
{
if (da.isEmpty()) return true;
// CodeQL [cpp/float-equality]: intentional exact comparison in dynamic type system
return other != da.convert<double>();
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/src/SplitterChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SplitterChannel::~SplitterChannel()
{
try
{
close();
SplitterChannel::close();
}
catch (...)
{
Expand Down
8 changes: 1 addition & 7 deletions Foundation/src/Var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,5 @@ std::string Var::toString(const Var& any)
return res;
}

/*
Var& Var::structIndexOperator(VarHolderImpl<Struct<int>>* pStr, int n) const
{
return pStr->operator[](n);
}
*/

} // namespace Poco::Dynamic

1 change: 0 additions & 1 deletion Foundation/src/VarIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "Poco/Dynamic/VarIterator.h"
#include "Poco/Dynamic/Var.h"
//#include "Poco/Dynamic/Struct.h"
#undef min
#undef max
#include <limits>
Expand Down
6 changes: 0 additions & 6 deletions JSON/include/Poco/JSON/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,19 +604,16 @@ class VarHolderImpl<JSON::Object::Ptr>: public VarHolder

void convert(DateTime& /*val*/) const override
{
//TODO: val = _val;
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
}

void convert(LocalDateTime& /*ldt*/) const override
{
//TODO: ldt = _val.timestamp();
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
}

void convert(Timestamp& /*ts*/) const override
{
//TODO: ts = _val.timestamp();
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
}

Expand Down Expand Up @@ -744,19 +741,16 @@ class VarHolderImpl<JSON::Object>: public VarHolder

void convert(DateTime& /*val*/) const override
{
//TODO: val = _val;
throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime");
}

void convert(LocalDateTime& /*ldt*/) const override
{
//TODO: ldt = _val.timestamp();
throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime");
}

void convert(Timestamp& /*ts*/) const override
{
//TODO: ts = _val.timestamp();
throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp");
}

Expand Down
4 changes: 2 additions & 2 deletions JSON/include/Poco/JSON/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class JSON_API Parser: private ParserImpl
/// Returns the Handler.

Dynamic::Var asVar() const;
/// Returns the result of parsing;
/// Returns the result of parsing

Dynamic::Var result() const;
/// Returns the result of parsing as Dynamic::Var;
/// Returns the result of parsing as Dynamic::Var

private:
Parser(const Parser&);
Expand Down
4 changes: 2 additions & 2 deletions JSON/include/Poco/JSON/ParserImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class JSON_API ParserImpl
/// Returns the Handler.

Dynamic::Var asVarImpl() const;
/// Returns the result of parsing;
/// Returns the result of parsing

Dynamic::Var resultImpl() const;
/// Returns the result of parsing as Dynamic::Var;
/// Returns the result of parsing as Dynamic::Var

private:
ParserImpl(const ParserImpl&);
Expand Down
21 changes: 0 additions & 21 deletions JSON/src/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,6 @@ Poco::OrderedDynamicStruct Object::makeOrderedStruct(const Object::Ptr& obj)
return makeStructImpl<Poco::OrderedDynamicStruct>(obj);
}

/*
void Object::resetOrdDynStruct() const
{
if (!_pOrdStruct)
_pOrdStruct = new Poco::OrderedDynamicStruct;
else
_pOrdStruct->clear();
}
*/


/*
void Object::resetDynStruct() const
{
if (!_pStruct)
_pStruct = new Poco::DynamicStruct;
else
_pStruct->clear();
}*/


Object::operator const Poco::DynamicStruct& () const
{
if (_values.empty())
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/HTTPAuthenticationParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Net_API HTTPAuthenticationParams: public NameValueCollection
virtual ~HTTPAuthenticationParams();
/// Destroys the HTTPAuthenticationParams.

HTTPAuthenticationParams& operator = (const HTTPAuthenticationParams& authParams);
HTTPAuthenticationParams& operator = (const HTTPAuthenticationParams& authParams) = default;
/// Assigns the content of another HTTPAuthenticationParams.

void fromAuthInfo(const std::string& authInfo);
Expand Down
4 changes: 2 additions & 2 deletions Net/include/Poco/Net/ICMPPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Net_API ICMPPacket
/// Returns raw ICMP packet. ICMP header and data are included in the returned packet.

int packetSize() const;
/// Returns the total length of packet (header + data);
/// Returns the total length of packet (header + data)

Poco::UInt16 sequence() const;
/// Returns the most recent sequence number generated.
Expand All @@ -52,7 +52,7 @@ class Net_API ICMPPacket
/// Returns data size.

int maxPacketSize() const;
/// Returns the total length of packet (header + data);
/// Returns the total length of packet (header + data)

struct timeval time(Poco::UInt8* buffer = nullptr, int length = 0) const;
/// Returns current epoch time if either buffer or length are equal to zero.
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/ICMPv4PacketImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Net_API ICMPv4PacketImpl : public ICMPPacketImpl
/// Destructor.

int packetSize() const;
/// Returns the total length of packet (header + data);
/// Returns the total length of packet (header + data)

struct timeval time(Poco::UInt8* buffer = nullptr, int length = 0) const;
/// Returns current epoch time if either buffer or length are equal to zero.
Expand Down
1 change: 1 addition & 0 deletions Net/include/Poco/Net/SocketConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SocketConnector
///
/// The overriding method must call the baseclass implementation first.
{
// CodeQL [cpp/local-address-stored]: reactor lifetime managed by caller; outlives connector by design
_pReactor = &reactor;
_pReactor->addEventHandler(_socket, Poco::NObserver<SocketConnector, ReadableNotification>(*this, &SocketConnector::onReadable));
_pReactor->addEventHandler(_socket, Poco::NObserver<SocketConnector, WritableNotification>(*this, &SocketConnector::onWritable));
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/SocketNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Net_API SocketNotifier: public Poco::RefCountedObject
/// Returns true if there are subscribers.

std::size_t countObservers() const;
/// Returns the number of subscribers;
/// Returns the number of subscribers

Socket socket() const;
/// Returns the socket.
Expand Down
6 changes: 0 additions & 6 deletions Net/src/DNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,6 @@ int punycode_encode(size_t input_length_orig, const punycode_uint input[], size_
if (max_out - out < 2) return punycode_big_output;
output[out++] = (char) input[j];
}
/* else if (input[j] < n) return punycode_bad_input; */
/* (not needed for Punycode with unsigned code points) */
}

h = b = (punycode_uint) out;
Expand All @@ -550,8 +548,6 @@ int punycode_encode(size_t input_length_orig, const punycode_uint input[], size_

for (m = maxint, j = 0; j < input_length; ++j)
{
/* if (basic(input[j])) continue; */
/* (not needed for Punycode) */
if (input[j] >= n && input[j] < m) m = input[j];
}

Expand Down Expand Up @@ -666,8 +662,6 @@ int punycode_decode(size_t input_length, const char input[], size_t *output_leng

/* Insert n at position i of the output: */

/* not needed for Punycode: */
/* if (basic(n)) return punycode_bad_input; */
if (out >= max_out) return punycode_big_output;

std::memmove(output + i + 1, output + i, (out - i) * sizeof *output);
Expand Down
2 changes: 1 addition & 1 deletion Net/src/FTPClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ FTPClientSession::FTPClientSession(const StreamSocket& socket,
_pControlSocket->setReceiveTimeout(_timeout);
if (readWelcomeMessage)
{
receiveServerReadyReply();
FTPClientSession::receiveServerReadyReply();
}
else
{
Expand Down
8 changes: 0 additions & 8 deletions Net/src/HTTPAuthenticationParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ HTTPAuthenticationParams::~HTTPAuthenticationParams()
}


HTTPAuthenticationParams& HTTPAuthenticationParams::operator = (const HTTPAuthenticationParams& authParams)
{
NameValueCollection::operator = (authParams);

return *this;
}


void HTTPAuthenticationParams::fromAuthInfo(const std::string& authInfo)
{
parse(authInfo.begin(), authInfo.end());
Expand Down
1 change: 1 addition & 0 deletions Net/src/HTTPClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ std::ostream& HTTPClientSession::sendRequest(HTTPRequest& request)
if (!_proxyConfig.host.empty() && !bypassProxy())
{
std::string prefix = proxyRequestPrefix();
// CodeQL [cpp/auth-bypass]: proxy prefix rewriting, not authentication logic
if (!prefix.empty() && request.getURI().compare(0, 7, "http://") != 0 && request.getURI().compare(0, 8, "https://") != 0)
request.setURI(prefix + request.getURI());
if (keepAlive) request.set(HTTPMessage::PROXY_CONNECTION, HTTPMessage::CONNECTION_KEEP_ALIVE);
Expand Down
15 changes: 9 additions & 6 deletions Net/src/ICMPv4PacketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@ std::string ICMPv4PacketImpl::errorDescription(unsigned char* buffer, int length

type = icp->type;
MessageType msgType = static_cast<MessageType>(type);
code = icp->code;
code = static_cast<int>(icp->code);
std::ostringstream err;

switch (msgType)
{
case DESTINATION_UNREACHABLE_TYPE:
if (code >= NET_UNREACHABLE && code < DESTINATION_UNREACHABLE_UNKNOWN)
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(NET_UNREACHABLE) && code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN))

Check warning

Code scanning / CodeQL

Comparison result is always the same

Comparison is always true because code >= 0.

Copilot Autofix

AI about 1 month ago

In general, to fix this type of issue you want the comparison to express a condition that can be either true or false given the actual runtime range of the operands. If part of a compound condition is provably always true (for example, checking that an unsigned‑derived value is >= 0), that part should be removed or the type/range assumptions revisited.

For this specific case in ICMPv4PacketImpl::errorDescription (Net/src/ICMPv4PacketImpl.cpp), the intent is to ensure code is within the valid range for indexing the corresponding error‑description arrays. Because code is derived from an ICMP header code field, which is an 8‑bit non‑negative value, only the upper bound of the range check is meaningful. The best fix that preserves behaviour is to remove the redundant lower‑bound checks while keeping the upper‑bound checks. Concretely:

  • In the DESTINATION_UNREACHABLE_TYPE case, change if (code >= static_cast<int>(NET_UNREACHABLE) && code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN)) to if (code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN)).
  • In the REDIRECT_MESSAGE_TYPE case, similarly drop the code >= static_cast<int>(REDIRECT_NETWORK) part.
  • In the TIME_EXCEEDED_TYPE case, drop the code >= static_cast<int>(TIME_TO_LIVE) part.

No new methods or imports are needed; we only simplify the if conditions in the shown function.

Suggested changeset 1
Net/src/ICMPv4PacketImpl.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Net/src/ICMPv4PacketImpl.cpp b/Net/src/ICMPv4PacketImpl.cpp
--- a/Net/src/ICMPv4PacketImpl.cpp
+++ b/Net/src/ICMPv4PacketImpl.cpp
@@ -215,8 +215,8 @@
 	switch (msgType)
 	{
 	case DESTINATION_UNREACHABLE_TYPE:
-		// lower-bound check is defensive (enum values may change)
-		if (code >= static_cast<int>(NET_UNREACHABLE) && code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN))
+		// check that code is within bounds of DESTINATION_UNREACHABLE_CODE
+		if (code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN))
 			err << DESTINATION_UNREACHABLE_CODE[code];
 		else
 			err << DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_UNKNOWN];
@@ -227,16 +227,16 @@
 		break;
 
 	case REDIRECT_MESSAGE_TYPE:
-		// lower-bound check is defensive (enum values may change)
-		if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
+		// check that code is within bounds of REDIRECT_MESSAGE_CODE
+		if (code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
 			err << REDIRECT_MESSAGE_CODE[code];
 		else
 			err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
 		break;
 
 	case TIME_EXCEEDED_TYPE:
-		// lower-bound check is defensive (enum values may change)
-		if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
+		// check that code is within bounds of TIME_EXCEEDED_CODE
+		if (code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
 			err << TIME_EXCEEDED_CODE[code];
 		else
 			err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
EOF
@@ -215,8 +215,8 @@
switch (msgType)
{
case DESTINATION_UNREACHABLE_TYPE:
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(NET_UNREACHABLE) && code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN))
// check that code is within bounds of DESTINATION_UNREACHABLE_CODE
if (code < static_cast<int>(DESTINATION_UNREACHABLE_UNKNOWN))
err << DESTINATION_UNREACHABLE_CODE[code];
else
err << DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_UNKNOWN];
@@ -227,16 +227,16 @@
break;

case REDIRECT_MESSAGE_TYPE:
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
// check that code is within bounds of REDIRECT_MESSAGE_CODE
if (code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
err << REDIRECT_MESSAGE_CODE[code];
else
err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
break;

case TIME_EXCEEDED_TYPE:
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
// check that code is within bounds of TIME_EXCEEDED_CODE
if (code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
err << TIME_EXCEEDED_CODE[code];
else
err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
err << DESTINATION_UNREACHABLE_CODE[code];
else
err << DESTINATION_UNREACHABLE_CODE[DESTINATION_UNREACHABLE_UNKNOWN];
Expand All @@ -225,22 +226,24 @@ std::string ICMPv4PacketImpl::errorDescription(unsigned char* buffer, int length
break;

case REDIRECT_MESSAGE_TYPE:
if (code >= REDIRECT_NETWORK && code < REDIRECT_MESSAGE_UNKNOWN)
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))

Check warning

Code scanning / CodeQL

Comparison result is always the same

Comparison is always true because code >= 0.

Copilot Autofix

AI about 1 month ago

In general, when a comparison is always the same truth value, remove or adjust the redundant part so that the condition can actually distinguish valid and invalid ranges, or rewrite the logic in terms of clearly defined bounds. Here, the intent in the REDIRECT_MESSAGE_TYPE case is to use code as an index into REDIRECT_MESSAGE_CODE only when it is in the valid range of redirect codes and fall back to an “unknown” entry otherwise.

The best fix while preserving behavior is to keep only the upper‑bound check, because code is already known to be non‑negative: replace

if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
    err << REDIRECT_MESSAGE_CODE[code];
else
    err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];

with

if (code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
    err << REDIRECT_MESSAGE_CODE[code];
else
    err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];

This leaves indexing logic unchanged for all non‑negative code values and removes the redundant condition that CodeQL flags. No new methods, imports, or definitions are needed; the change is localized to the REDIRECT_MESSAGE_TYPE case in Net/src/ICMPv4PacketImpl.cpp, around lines 229–235.

Suggested changeset 1
Net/src/ICMPv4PacketImpl.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Net/src/ICMPv4PacketImpl.cpp b/Net/src/ICMPv4PacketImpl.cpp
--- a/Net/src/ICMPv4PacketImpl.cpp
+++ b/Net/src/ICMPv4PacketImpl.cpp
@@ -227,8 +227,8 @@
 		break;
 
 	case REDIRECT_MESSAGE_TYPE:
-		// lower-bound check is defensive (enum values may change)
-		if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
+		// check that code is within the known redirect message range
+		if (code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
 			err << REDIRECT_MESSAGE_CODE[code];
 		else
 			err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
EOF
@@ -227,8 +227,8 @@
break;

case REDIRECT_MESSAGE_TYPE:
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(REDIRECT_NETWORK) && code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
// check that code is within the known redirect message range
if (code < static_cast<int>(REDIRECT_MESSAGE_UNKNOWN))
err << REDIRECT_MESSAGE_CODE[code];
else
err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
err << REDIRECT_MESSAGE_CODE[code];
else
err << REDIRECT_MESSAGE_CODE[REDIRECT_MESSAGE_UNKNOWN];
break;

case TIME_EXCEEDED_TYPE:
if (code >= TIME_TO_LIVE && code < TIME_EXCEEDED_UNKNOWN)
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))

Check warning

Code scanning / CodeQL

Comparison result is always the same

Comparison is always true because code >= 0.

Copilot Autofix

AI about 1 month ago

In general, to fix “comparison result is always the same” issues, you either (1) remove the redundant part of the condition if it truly adds no value, or (2) adjust the operands or types to match the intended semantics if the redundancy is accidental. Here, the pattern is repeated for several ICMP message types: “lower-bound check is defensive (enum values may change)” followed by a code >= ... && code < ... guard. For the TIME_EXCEEDED_TYPE case, CodeQL determined the lower bound is always satisfied, so the first comparison is dead code.

The safest fix that does not change observable behavior is to drop the always‑true lower‑bound comparison in this specific case and rely solely on the upper bound check, which is the one that actually protects the array indexing. Concretely, in Net/src/ICMPv4PacketImpl.cpp, within ICMPv4PacketImpl::errorDescription, in the case TIME_EXCEEDED_TYPE: block, replace:

		// lower-bound check is defensive (enum values may change)
		if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
			err << TIME_EXCEEDED_CODE[code];
		else
			err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];

with:

		if (code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
			err << TIME_EXCEEDED_CODE[code];
		else
			err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];

This keeps the same behavior for all possible code values (since the removed condition was always true under the current type/value assumptions) and removes the condition that the analyzer flagged. No additional methods, imports, or definitions are required.

Suggested changeset 1
Net/src/ICMPv4PacketImpl.cpp

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Net/src/ICMPv4PacketImpl.cpp b/Net/src/ICMPv4PacketImpl.cpp
--- a/Net/src/ICMPv4PacketImpl.cpp
+++ b/Net/src/ICMPv4PacketImpl.cpp
@@ -235,8 +235,7 @@
 		break;
 
 	case TIME_EXCEEDED_TYPE:
-		// lower-bound check is defensive (enum values may change)
-		if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
+		if (code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
 			err << TIME_EXCEEDED_CODE[code];
 		else
 			err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
EOF
@@ -235,8 +235,7 @@
break;

case TIME_EXCEEDED_TYPE:
// lower-bound check is defensive (enum values may change)
if (code >= static_cast<int>(TIME_TO_LIVE) && code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
if (code < static_cast<int>(TIME_EXCEEDED_UNKNOWN))
err << TIME_EXCEEDED_CODE[code];
else
err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
err << TIME_EXCEEDED_CODE[code];
else
err << TIME_EXCEEDED_CODE[TIME_EXCEEDED_UNKNOWN];
break;

case PARAMETER_PROBLEM_TYPE:
if (POINTER_INDICATES_THE_ERROR != code)
code = PARAMETER_PROBLEM_UNKNOWN;
if (static_cast<int>(POINTER_INDICATES_THE_ERROR) != code)
code = static_cast<int>(PARAMETER_PROBLEM_UNKNOWN);
err << PARAMETER_PROBLEM_CODE[code] << ": error in octet #" << pointer;
break;

Expand Down
2 changes: 2 additions & 0 deletions Net/src/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ std::string IPAddress::trimIPv6(const std::string& v6Addr)
if ((dblColOcc > 1) ||
(std::count(v6addr.begin(), v6addr.end(), ':') > 8) ||
(v6addr.find(":::") != std::string::npos) ||
// CodeQL [cpp/constant-comparison]: intentional IPv6 validation — checks for trailing single colon
((len >= 2) && ((v6addr[len-1] == ':') && v6addr[len-2] != ':')))
{
return v6addr;
Expand All @@ -581,6 +582,7 @@ IPAddress IPAddress::parse(const std::string& addr)
bool IPAddress::tryParse(const std::string& addr, IPAddress& result)
{
IPv4AddressImpl impl4(IPv4AddressImpl::parse(addr));
// CodeQL [cpp/auth-bypass]: IP address parsing, not authentication
if (impl4 != IPv4AddressImpl() || trim(addr) == "0.0.0.0")
{
result.newIPv4(impl4.addr());
Expand Down
4 changes: 2 additions & 2 deletions Net/src/MailMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ void MailMessage::read(std::istream& istr, PartHandler& handler)
}
else
{
StringPartHandler handler(_content);
readPart(istr, *this, handler);
StringPartHandler stringHandler(_content);
readPart(istr, *this, stringHandler);
}
}

Expand Down
Loading
Loading