Skip to content

specconv: fix systemd property handling bugs#5130

Closed
lukefr09 wants to merge 1 commit intoopencontainers:mainfrom
lukefr09:fix-systemd-property-handling
Closed

specconv: fix systemd property handling bugs#5130
lukefr09 wants to merge 1 commit intoopencontainers:mainfrom
lukefr09:fix-systemd-property-handling

Conversation

@lukefr09
Copy link
Copy Markdown

Summary

Fix two bugs in systemd property annotation handling:

  1. Panic on property name "Sec": initSystemdProps panics when a systemd property annotation has the name exactly "Sec" (after prefix stripping). TrimSuffix("Sec", "Sec") returns an empty string, and trimName[len(trimName)-1] causes an index-out-of-bounds panic. Add a len(trimName) > 0 guard.

  2. Negative value wrapping in convertSecToUSec: Negative signed integer values (int16, int32, int64) are silently converted to huge uint64 values via unsigned wrapping. For example, int16(-1) becomes uint64(18446744073709551615) * 1000000. Add negative value checks for the signed types and float64.

Found during code review.

Signed-off-by: Luke Hinds luke@stacklok.com

Fix two bugs in systemd property annotation handling:

1. initSystemdProps panics when a property name is exactly "Sec".
   TrimSuffix("Sec", "Sec") returns an empty string, and the
   subsequent index trimName[len(trimName)-1] causes an out-of-bounds
   panic. Add a len(trimName) > 0 guard before indexing.

2. convertSecToUSec silently wraps negative signed integer values to
   huge uint64 values. For example, int16(-1) becomes
   uint64(18446744073709551615) * 1000000, which overflows. Add
   negative value checks for the signed integer types (int16, int32,
   int64) and float64.

Signed-off-by: Luke Hinds <luke@stacklok.com>
@lukefr09 lukefr09 marked this pull request as draft February 26, 2026 05:58
@lukefr09 lukefr09 closed this Feb 26, 2026
@lukefr09
Copy link
Copy Markdown
Author

Apologies, this was submitted by an automated tool that wasn't properly scoped. Shouldn't have hit upstream. Closing and sorry for the noise.
Luke

Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

IMO overflow in convertSecToUSec due to negative inputs results in either high or random xxxUsec property values, which is not ideal but I don't see any big issue here.

Also, -1 might be a valid value (meaning "infinity" in systemd lingo), and while we currently don't handle it correctly (I guess this should be passed as is, not multiplied), it is not a big deal either.

Still might worth fixing, but is kind of low priority

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants