Skip to content

Sbat code generation improves#793

Open
freddy77 wants to merge 18 commits intorhboot:mainfrom
freddy77:sbat_gen
Open

Sbat code generation improves#793
freddy77 wants to merge 18 commits intorhboot:mainfrom
freddy77:sbat_gen

Conversation

@freddy77
Copy link

This PR contains improves to the code to generate SBAT files from SbatLevel_Variable.txt.
Mostly are style changes, some others more strict checks in order to avoid some possible errors.
Specific commits contain more explanation.

  • Make some functions static
  • Constify some variables
  • Fix readfile error check
  • Factor out and reuse function to clear revocation list
  • Use tabs for indentation
  • Use bool for epochfound
  • Use unsigned for date field
  • Reduce indentation
  • Check file read error
  • Restrict some variable scope
  • Make errors more verbose
  • Add more explicit check on revocation list format
  • Make sure revocation string is always terminated
  • Handle not newline terminated last line correctly
  • Better checks for revocation lines
  • Minor output format style changes
  • Don't ignore first program argument
  • Declare parameters for writefile function

Frediano Ziglio added 18 commits March 23, 2026 11:44
Not used outside of the program.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
They should not be changed.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
The function was always returning true (!= 0), make it returns 0
on success like writefile function.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
The rest of the file use tabs.
Just style change.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
More readable.
Just style change.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
The number can't be negative, this allows sscanf to be more strict
about it.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Use continue to reduce function indentation.
Just style change.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Although unlikely fgets can return NULL with file read errors.
Detect them.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Just style change.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Give some indication of the failures.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
The epoch line should be the first revocation list.
There should be no 2 epoch revocations.
Other revocations should be after the epoch.
These should be detected probably by compiling the resulting
code but better to be explicit.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
In case the revocation string is the epoch revocation the
string was not terminated.
Currently the string is not used but better to be safer.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
The code was potentially stripping last not-newline character from
last line.
Although most editors finish text files with a new line this is not
always true and could lead to security issues (think about a
"component,12" revocation parsed as a "component,1" revocation).
Normalize the string line stripping only the newline terminator.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Make sure they are in the format XXXX,nn where X are not commas or
spaces and n are just digits.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Add an "autogenerated" comment.
Separate default GEN_SBAT_VAR_DEFS_H_ definition with an extra
empty line.
No functional changes.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
If you had more than 1 argument the first was ignored treating
as no arguments were given.
Instead ignore remaining argument.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
No parameters declaration is more K&R or C++ style.
Some recent compilers complain about it.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
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.

1 participant