vtctl: fix nil pointer dereference in SNAPSHOT keyspace creation#19120
vtctl: fix nil pointer dereference in SNAPSHOT keyspace creation#19120
Conversation
When creating a SNAPSHOT keyspace, if the base keyspace has no VSchema (NoNode error), the code would set ksvs.Keyspace to an empty vschema, but then unconditionally try to clone from bksvs.Keyspace. Since bksvs is nil when GetVSchema returns an error, this causes a panic. Fix by moving the clone into an else block so it only runs when GetVSchema succeeds. This matches the correct pattern already used in grpcvtctldserver/server.go. Signed-off-by: Nick Van Wiggeren <nick@planetscale.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19120 +/- ##
==========================================
+ Coverage 69.87% 69.88% +0.01%
==========================================
Files 1613 1613
Lines 216002 216024 +22
==========================================
+ Hits 150939 150978 +39
+ Misses 65063 65046 -17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
The legacy vtctl[client] client has been deprecated since v18.0 (I would like to remove it entirely in v24 or v25). It's fine to fix this, I suppose... but does this same issue exist in vtctldclient?
The current/supported client implementation is here:
vitess/go/cmd/vtctldclient/command/keyspaces.go
Lines 123 to 206 in 93e4601
And the server side implementation for the current/supported client/server implementation is here:
vitess/go/vt/vtctl/grpcvtctldserver/server.go
Lines 913 to 1023 in 4787512
I'm guessing that by this comment:
This matches the correct pattern already used in grpcvtctldserver/server.go.
The issue does not exist in the current/supported client/server implementation. 🙂
yep! I debated not opening this at all since it's deprecated, but once I knew it was a problem I couldn't stop myself. |
Description
When creating a SNAPSHOT keyspace, if the base keyspace has no VSchema (NoNode error), the code would set ksvs.Keyspace to an empty vschema, but then unconditionally try to clone from bksvs.Keyspace. Since bksvs is nil when GetVSchema returns an error, this causes a panic.
Fix by moving the clone into an else block so it only runs when GetVSchema succeeds. This matches the correct pattern already used in grpcvtctldserver/server.go.
Related Issue(s)
Fixes #19134
Checklist
Deployment Notes
AI Disclosure
This was discovered by doing some thorough analyses with AI and then validating the findings.