Address review: fix NULL asymmetry in backend sync decisions (PR #5511)

- BackendSyncDecision.cpp: treat asymmetric NULLs as mismatches
  (client=NULL + backend="bob" → SYNC_USER, not SYNC_NONE)
- Tests: replace weak null assertions (a >= 0 always true) with
  specific checks for SYNC_USER/SYNC_SCHEMA on asymmetric NULLs,
  both-null → no sync, schema asymmetric null (+2 tests, plan 15→17)
pull/5511/head
René Cannaò 1 month ago
parent bc4251d589
commit b51f50b96b

@ -20,7 +20,12 @@ int determine_backend_sync_actions(
int actions = SYNC_NONE;
// Username mismatch → CHANGE USER required
if (client_user && backend_user) {
// Asymmetric NULLs (one set, other not) count as mismatch
if (client_user == nullptr && backend_user != nullptr) {
actions |= SYNC_USER;
} else if (client_user != nullptr && backend_user == nullptr) {
actions |= SYNC_USER;
} else if (client_user && backend_user) {
if (strcmp(client_user, backend_user) != 0) {
actions |= SYNC_USER;
}
@ -29,7 +34,11 @@ int determine_backend_sync_actions(
// Schema mismatch → USE <db> required
// Only check if usernames match (user change handles schema too)
if (!(actions & SYNC_USER)) {
if (client_schema && backend_schema) {
if (client_schema == nullptr && backend_schema != nullptr) {
actions |= SYNC_SCHEMA;
} else if (client_schema != nullptr && backend_schema == nullptr) {
actions |= SYNC_SCHEMA;
} else if (client_schema && backend_schema) {
if (strcmp(client_schema, backend_schema) != 0) {
actions |= SYNC_SCHEMA;
}

@ -52,15 +52,24 @@ static void test_multiple_mismatches() {
static void test_null_handling() {
// null users — no crash
// Asymmetric NULL: one side null, other not → mismatch
int a = determine_backend_sync_actions(nullptr, "user", "db", "db", true, true);
ok(a == SYNC_NONE || a >= 0, "null client_user: no crash");
ok((a & SYNC_USER) != 0, "null client_user + non-null backend → SYNC_USER");
a = determine_backend_sync_actions("user", nullptr, "db", "db", true, true);
ok(a == SYNC_NONE || a >= 0, "null backend_user: no crash");
ok((a & SYNC_USER) != 0, "non-null client_user + null backend → SYNC_USER");
// Both null → no mismatch
a = determine_backend_sync_actions(nullptr, nullptr, "db", "db", true, true);
ok(a == SYNC_NONE, "both users null → no sync");
// Schema asymmetric null
a = determine_backend_sync_actions("user", "user", nullptr, "db", true, true);
ok((a & SYNC_SCHEMA) != 0, "null client_schema + non-null backend → SYNC_SCHEMA");
}
int main() {
plan(15);
plan(17);
int rc = test_init_minimal();
ok(rc == 0, "test_init_minimal() succeeds");
@ -70,8 +79,8 @@ int main() {
test_user_and_schema_mismatch(); // 2
test_autocommit_mismatch(); // 2
test_multiple_mismatches(); // 2
test_null_handling(); // 2
// Total: 1+2+2+2+2+2+2+2 = 15
test_null_handling(); // 4
// Total: 1+2+2+2+2+2+2+4 = 17
test_cleanup_minimal();
return exit_status();

Loading…
Cancel
Save