LibertyReader: guard null FuncExpr/members on malformed Liberty #373
Open
ranaumarnadeem wants to merge 1 commit into
Open
LibertyReader: guard null FuncExpr/members on malformed Liberty #373ranaumarnadeem wants to merge 1 commit into
ranaumarnadeem wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request fixes potential null-pointer dereferences in LibertyReader.cc by adding null checks for member_attr in makeBundlePort, and for func_expr and tri_disable_expr in makePortFuncs. It also adds a new test case malformed_ports to ensure that malformed port attributes trigger warnings instead of causing crashes. There are no review comments to evaluate, so no further feedback is provided.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix three null-dereference crashes in LibertyReader on malformed Liberty
Reading a Liberty file with certain malformed port attributes crashes OpenSTA
with a SIGSEGV. Three sites in
LibertyReaderdereference a pointer that canlegitimately be null on malformed input. This adds the missing null guards
(matching the existing guarded sibling path) so the reader emits a warning and
continues, plus a focused regression test.
reoroduce via this
A few lines of Liberty +
read_liberty:functionreferences an undeclared pin (e.g. a typo):pin (Z) { direction : output; function : "A & NOPIN"; }three_statereferences an undeclared pin:pin (Z) { direction : output; three_state : "BADPIN"; function : "A"; }bundlegroup with nomembers:bundle (B) { direction : output; }Root cause
LibertyReader::makePortFuncs()callsparseFunc()forfunctionandthree_state.parseFunc()returnsnullptrfor an expression that parsesbut references an unknown port (
LibExprReader::makeFuncExprPortwarns andreturns null). The results were dereferenced unconditionally
(
func_expr->checkSize(port),tri_disable_expr->invert()).LibertyReader::makeBundlePort()callsfindComplexAttr("members"), whichreturns
nullptrwhen the attribute is absent, then dereferences it in therange-for (
member_attr->values()) and leaks the allocatedConcretePortSeq.The correct pattern already exists in the same file:
makeSeqFunc()guards withif (expr && expr->checkSize(size)). These three sites simply missed it.Fix
function:if (func_expr && func_expr->checkSize(port))(mirrors makeSeqFunc).three_state: wrap the tristate handling inif (tri_disable_expr) { ... }.bundle: ifmembersis absent,warn(1315, ...) "bundle <name> missing members."and return (also avoids the leak).Valid Liberty is unaffected — the guarded expressions are non-null there. On
malformed input the reader now warns and continues; the cell loads minus the
bad attribute.
Tests
New regression
liberty/test/liberty_malformed_ports.{lib,tcl}(+ golden.ok),registered in
liberty/test/CMakeLists.txt. Oneread_libertyexercises allthree paths; the golden pins the warnings and confirms recovery
Verification
ctest -R tcl.liberty: 33/33 pass (32 existing + the new test).ctestsuite: 6083/6083 pass, zero regressions.Files changed
liberty/LibertyReader.cc— three null guards (+ new warning id 1315)liberty/test/liberty_malformed_ports.lib— new (test input)liberty/test/liberty_malformed_ports.tcl— new (test driver)liberty/test/liberty_malformed_ports.ok— new (golden)liberty/test/CMakeLists.txt— register the new test