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

guest: clean up and unify reading the timestamp from a variable buffer #76

Closed
4 tasks
erichte-ibm opened this issue Nov 17, 2023 · 1 comment
Closed
4 tasks
Milestone

Comments

@erichte-ibm
Copy link
Collaborator

In multiple places in the code (namely guest_svc_read.c:read_path()), we load in data from a variable, then proceed to do some level of validation which mostly consists of checking that the buffer is an expected size before doing any parsing. As asked in PR #75 , the "expected" size of a buffer should be defined, documented, and probably abstracted out so that other places of the code can call a function to read in a particular variable and do this same validation.


From my understanding, the following conditions should be checked and handled on the buffer size:

  • size == 0 → error case, likely invalid file or some other I/O error. variables should not be completely empty
  • 0 < size < HEADER_LEN → error case, variable must contain at least the 16-byte header
  • size == HEADER_LEN → valid case, variable exists but contains no data
  • size > HEADER_LEN → valid case, data exists and can be parsed

Data read from a variable contains a header of 16 bytes, consisting of a 1-byte version number, then 15 bytes of timestamp, truncating the last pad so that the header remains aligned.


Cleaning this up will probably looking some like:

  • factor out header parsing into another function, perhaps variable_from_path()
  • remove references to TIMESTAMP_LEN and TIMESTAMP_LEN - 1 when referring to this header
  • actually parse and inspect the version number?
  • clean up any duplicate code paths that differentiated reading from a variable vs reading from a local file
@erichte-ibm erichte-ibm added this to the 1.0.0 milestone Nov 17, 2023
erichte-ibm pushed a commit to erichte-ibm/secvarctl that referenced this issue Nov 17, 2023
Move the existing print_timestamp function to common/util, and add a new
helper to handle reading and printing a timestamp from a variable buffer.

Prints the timestamp when using the read command, and when using verbose
levels in the verify command.

This commit is part of a larger work in progress on factoring out
loading data from a variable vs a file, see more information in open-power#76.

Co-developed-by: Eric Richter <[email protected]>
Signed-off-by: Sudhakar Kuppusamy <[email protected]>
This was referenced Nov 17, 2023
nick-child-ibm pushed a commit that referenced this issue Dec 8, 2023
Move the existing print_timestamp function to common/util, and add a new
helper to handle reading and printing a timestamp from a variable buffer.

Prints the timestamp when using the read command, and when using verbose
levels in the verify command.

This commit is part of a larger work in progress on factoring out
loading data from a variable vs a file, see more information in #76.

Co-developed-by: Eric Richter <[email protected]>
Signed-off-by: Sudhakar Kuppusamy <[email protected]>
@erichte-ibm
Copy link
Collaborator Author

Resolved in #77

nick-child-ibm pushed a commit that referenced this issue Feb 6, 2024
Move the existing print_timestamp function to common/util, and add a new
helper to handle reading and printing a timestamp from a variable buffer.

Prints the timestamp when using the read command, and when using verbose
levels in the verify command.

This commit is part of a larger work in progress on factoring out
loading data from a variable vs a file, see more information in #76.

Co-developed-by: Eric Richter <[email protected]>
Signed-off-by: Sudhakar Kuppusamy <[email protected]>
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

No branches or pull requests

1 participant