RDK-60607: Fix for y2k38 issue and integer overflow#442
RDK-60607: Fix for y2k38 issue and integer overflow#442karuna2git merged 17 commits intordkcentral:developfrom
Conversation
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
This PR updates rtmessage/rtrouted message timing and buffer-size handling to address y2k38-related timestamp sizing and integer overflow risks by widening several time/size fields to 64-bit and adding supporting encode/decode and message APIs.
Changes:
- Switch roundtrip timing fields (
T1..T5) inrtMessageHeaderfrom 32-bit/time_t usage to 64-bit encoding/decoding. - Add
rtMessage_SetUInt64/rtMessage_GetUInt64to transport 64-bit values via rtMessage. - Widen client read state counters/capacity to 64-bit and add checks to prevent negative/overflowed read sizes and oversize buffer reallocations.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/rtmessage/rtrouted.c | Uses 64-bit T* fields and strengthens read-size handling; updates timeout timing message parsing. |
| src/rtmessage/rtrouteBase.h | Widen rtConnectedClient byte counters/capacity to uint64_t. |
| src/rtmessage/rtrouteBase.c | Mirrors 64-bit read counter/capacity changes and roundtrip timestamp assignments. |
| src/rtmessage/rtMessageHeader.h | Changes T1..T5 types to uint64_t. |
| src/rtmessage/rtMessageHeader.c | Encodes/decodes timestamps as uint64_t and adjusts fixed header size constant. |
| src/rtmessage/rtMessage.h | Adds new UInt64 set/get APIs. |
| src/rtmessage/rtMessage.c | Implements UInt64 set/get via string serialization. |
| src/rtmessage/rtEncoder.h | Declares UInt64 encode/decode helpers. |
| src/rtmessage/rtEncoder.c | Implements UInt64 encode/decode using big-endian conversions. |
| src/rtmessage/rtConnection.c | Updates internal send API to carry 64-bit timing values and emits timing info via new UInt64 message fields. |
Comments suppressed due to low confidence (1)
src/rtmessage/rtrouted.c:134
rtRouted_TransactionTimingDetailsassumesT1..T5are monotonic seconds since boot and converts them to wall time viaboottime, but the timestamps are nowuint64_tand at leastT1/T4are populated elsewhere as nanoseconds. This will produce incorrect timestamps and durations (and can overflow when casting totime_t). Update the conversion to match the chosen unit (e.g., split ns intotv_sec/tv_nsec), and make sure allT*fields are generated in that same unit.
rtTime_Now(&uptime);
boottime = time(NULL) - uptime.tv_sec; /* To calculate actual boot time of the device
time(NULL) - Time since Epoch time(1st Jan 1970)
uptime.tv_sec - Time since boot of device */
rtLog_Info("=======================================================================");
timestamp.tv_sec = (time_t)header_details->T1 + boottime;
rtTime_ToString(×tamp, time_buff);
rtLog_Info("Consumer : %s", header_details->topic);
rtLog_Info("Provider : %s", header_details->reply_topic);
rtLog_Info("Time at which consumer sends the request to daemon : %s", time_buff);
memset(time_buff, 0, sizeof(time_buff));
timestamp.tv_sec = (time_t)header_details->T2 + boottime;
rtTime_ToString(×tamp, time_buff);
rtLog_Info("Time at which daemon receives the message from consumer: %s", time_buff);
memset(time_buff, 0, sizeof(time_buff));
timestamp.tv_sec = (time_t)header_details->T3 + boottime;
rtTime_ToString(×tamp, time_buff);
rtLog_Info("Time at which daemon writes to provider socket : %s", time_buff);
memset(time_buff, 0, sizeof(time_buff));
timestamp.tv_sec = (time_t)header_details->T4 + boottime;
rtTime_ToString(×tamp, time_buff);
rtLog_Info("Time at which provider sends back the response : %s", time_buff);
memset(time_buff, 0, sizeof(time_buff));
timestamp.tv_sec = (time_t)header_details->T5 + boottime;
rtTime_ToString(×tamp, time_buff);
rtLog_Info("Time at which daemon received the response : %s", time_buff);
rtLog_Info("Total duration : %lld seconds", (long long int)(header_details->T5 - header_details->T1));
rtLog_Info("=======================================================================");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverity Issue - Overflowed integer argumentThe cast of "msginfo->header.payload_length" to a signed type could result in a negative number. High Impact, CWE-190 Issue locationThis issue was discovered outside the diff for this Pull Request. You can find it at: |
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (2)
src/rtmessage/rtrouted.c:1570
clnt->bytes_readis nowuint64_tand is used as an array index in&clnt->read_buffer[clnt->bytes_read]. Ifbytes_readever exceedsSIZE_MAX, this index can overflow the pointer arithmetic on 32-bit platforms. Consider validatingclnt->bytes_read <= SIZE_MAX(and that it’s <=read_buffer_capacity) before forming the pointer passed torecv().
bytes_read = recv(clnt->fd, &clnt->read_buffer[clnt->bytes_read], bytes_to_read, MSG_NOSIGNAL);
if (bytes_read == -1)
src/rtmessage/rtrouteBase.c:367
clnt->bytes_readis auint64_tand is used to indexread_bufferin therecv()call. Without ensuringbytes_read <= SIZE_MAX(and withinread_buffer_capacity), pointer arithmetic can overflow on 32-bit platforms if the state is corrupted or a malformed header causes extreme sizes.
bytes_read = recv(clnt->fd, &clnt->read_buffer[clnt->bytes_read], bytes_to_read, MSG_NOSIGNAL);
if (bytes_read == -1)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: dshett549 <DEEPTHICHANDRASHEKAR_SHETTY@comcast.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reason For Change: y2k38 issue and integer overflow
Signed-off-by: dshett549 [[DEEPTHICHANDRASHEKAR_SHETTY@comcast.com]