Skip to content

Commit a1553ef

Browse files
committed
sqlite: refactor authz code validation logic
1 parent 9e96632 commit a1553ef

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

src/node_sqlite.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,8 @@ int DatabaseSync::AuthorizerCallback(void* user_data,
19671967
}
19681968

19691969
Local<Value> result;
1970-
if (!retval.ToLocal(&result) || result->IsUndefined() || result->IsNull()) {
1971-
// Missing return value
1970+
if (!retval.ToLocal(&result) || result->IsUndefined() || result->IsNull() ||
1971+
!result->IsInt32()) {
19721972
Local<Value> err = Exception::TypeError(
19731973
String::NewFromUtf8(
19741974
isolate,
@@ -1978,15 +1978,6 @@ int DatabaseSync::AuthorizerCallback(void* user_data,
19781978
return SQLITE_DENY;
19791979
}
19801980

1981-
if (!result->IsInt32()) {
1982-
Local<Value> err = Exception::TypeError(
1983-
String::NewFromUtf8(
1984-
isolate, "Authorizer callback return value must be an integer")
1985-
.ToLocalChecked());
1986-
db->StoreAuthorizerError(err);
1987-
return SQLITE_DENY;
1988-
}
1989-
19901981
int32_t int_result = result.As<Int32>()->Value();
19911982
if (int_result != SQLITE_OK && int_result != SQLITE_DENY &&
19921983
int_result != SQLITE_IGNORE) {

test/parallel/test-sqlite-authz.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ suite('DatabaseSync.prototype.setAuthorizer()', () => {
105105
assert.throws(() => {
106106
db.exec('SELECT 1');
107107
}, {
108-
message: 'Authorizer callback return value must be an integer'
108+
message: 'Authorizer callback must return an integer authorization code'
109109
});
110110
});
111111

0 commit comments

Comments
 (0)