Skip to content

fix: add NULL check for GvIOp in XML_Do_External_Parse#259

Draft
toddr-bot wants to merge 1 commit intomainfrom
koan.toddr.bot/fix-gviop-null-check
Draft

fix: add NULL check for GvIOp in XML_Do_External_Parse#259
toddr-bot wants to merge 1 commit intomainfrom
koan.toddr.bot/fix-gviop-null-check

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

Prevent segfault when ExternEnt handler returns an unopened filehandle (glob with no IO slot).

Why

GvIOp() returns NULL when a glob has never been opened. Both call sites in XML_Do_External_Parse (lexical glob ref at L2357 and bare glob at L2361) passed the result directly to newRV_inc(NULL), which dereferences the NULL pointer — instant segfault. While most handlers return properly opened filehandles, a buggy or incomplete handler could trigger this crash with no useful diagnostic.

How

Extract the GvIOp() result into a local IO *io variable and check for NULL before use. On NULL, croak() with a descriptive message instead of dereferencing.

Testing

  • Added 2 tests to t/extern_ent_lexical_glob.t: one for bare unopened glob, one for scalar ref (different code path but same area)
  • Full test suite passes

🤖 Generated with Claude Code

GvIOp() returns NULL when a glob has no IO slot (e.g., an unopened
filehandle). The two call sites in XML_Do_External_Parse passed the
result directly to newRV_inc(), which would dereference NULL and
segfault. Now we check for NULL and croak with a descriptive message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.45%. Comparing base (45216a7) to head (04b2db8).

Files with missing lines Patch % Lines
Expat/Expat.xs 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #259      +/-   ##
==========================================
+ Coverage   75.73%   76.45%   +0.72%     
==========================================
  Files           1        1              
  Lines        1092     1096       +4     
  Branches      342      344       +2     
==========================================
+ Hits          827      838      +11     
+ Misses         59       52       -7     
  Partials      206      206              
Flag Coverage Δ
perl 76.45% <66.66%> (+0.72%) ⬆️
xs 76.45% <66.66%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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