Skip to content

Commit f592978

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

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/node_sqlite.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,8 +1967,7 @@ 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() || !result->IsInt32()) {
19721971
Local<Value> err = Exception::TypeError(
19731972
String::NewFromUtf8(
19741973
isolate,
@@ -1978,15 +1977,6 @@ int DatabaseSync::AuthorizerCallback(void* user_data,
19781977
return SQLITE_DENY;
19791978
}
19801979

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-
19901980
int32_t int_result = result.As<Int32>()->Value();
19911981
if (int_result != SQLITE_OK && int_result != SQLITE_DENY &&
19921982
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)