Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(libsinsp): remove a few more UB warnings from integer copies #1481

Merged
merged 1 commit into from Nov 13, 2023

Conversation

LucaGuerra
Copy link
Contributor

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind cleanup

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area libsinsp

Does this PR require a change in the driver versions?

No

What this PR does / why we need it:

One (of many) changes for this: #1470 . In this case, we're removing a few warnings that are not concerning get_param(). We will be back with more refactorings there.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Signed-off-by: Luca Guerra <luca@guerra.sh>
@FedeDP
Copy link
Contributor

FedeDP commented Nov 13, 2023

/milestone 0.14.0

@poiana poiana added this to the 0.14.0 milestone Nov 13, 2023
Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Nov 13, 2023

LGTM label has been added.

Git tree hash: 0882c03e71d68950af64175a56c7f1a77f020726

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this!
/approve

@poiana
Copy link
Contributor

poiana commented Nov 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, LucaGuerra

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,LucaGuerra]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

addr.m_fields.m_sport = sinfo->m_ipv4info.m_fields.m_sport;
addr.m_fields.m_dip = *(uint32_t*)db;
addr.m_fields.m_dip = sinfo->m_ipv4info.m_fields.m_dip;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why m_sport and m_dport don't need a memcpy (here and in line 529 or so)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the source and destination fields are the same length. memcpying there would be pointless I think. Although later (on line 499) those fields are accessed with an array, do you think we need to memcpy() there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait. These are just copying from one struct to another. This is fine.

I can't really follow what's going on in the other chunk ATM (what is the source: an actual well behaved C struct or a packed struct at an arbitrary address in the event), so here's a general comment:

memcpy instead of an assignment is not about the size (it obviously must be the same for the source and destination) but about alignment: the destination is aligned properly for the type (simply because it is of that type) but if the source is a packed struct (or a random char* ptr) then technically treating it as a pointer to anything other than char is UB.

(AFAIK that also includes taking the address of a misaligned member in a packed struct)

@poiana poiana merged commit 99f764d into falcosecurity:master Nov 13, 2023
26 checks passed
@LucaGuerra LucaGuerra deleted the fix/memcpy-network-ub branch November 14, 2023 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants