Commit 9327abb4 authored by John Schanck's avatar John Schanck
Browse files

Bug 1849056 - handle failures of CryptoBuffer::ToArrayBuffer. r=tschuster,webidl,smaug a=pascalc

parent 37464978
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -55,11 +55,15 @@ JSObject* AuthenticatorAssertionResponse::WrapObject(
}

void AuthenticatorAssertionResponse::GetAuthenticatorData(
    JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
    JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
  if (!mAuthenticatorDataCachedObj) {
    mAuthenticatorDataCachedObj = mAuthenticatorData.ToArrayBuffer(aCx);
    if (!mAuthenticatorDataCachedObj) {
      aRv.NoteJSContextException(aCx);
      return;
    }
  }
  aRetVal.set(mAuthenticatorDataCachedObj);
  aValue.set(mAuthenticatorDataCachedObj);
}

nsresult AuthenticatorAssertionResponse::SetAuthenticatorData(
@@ -71,11 +75,15 @@ nsresult AuthenticatorAssertionResponse::SetAuthenticatorData(
}

void AuthenticatorAssertionResponse::GetSignature(
    JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
    JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
  if (!mSignatureCachedObj) {
    mSignatureCachedObj = mSignature.ToArrayBuffer(aCx);
    if (!mSignatureCachedObj) {
      aRv.NoteJSContextException(aCx);
      return;
    }
  aRetVal.set(mSignatureCachedObj);
  }
  aValue.set(mSignatureCachedObj);
}

nsresult AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) {
@@ -86,17 +94,21 @@ nsresult AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) {
}

void AuthenticatorAssertionResponse::GetUserHandle(
    JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
    JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
  // Per
  // https://w3c.github.io/webauthn/#ref-for-dom-authenticatorassertionresponse-userhandle%E2%91%A0
  // this should return null if the handle is unset.
  if (mUserHandle.IsEmpty()) {
    aRetVal.set(nullptr);
    aValue.set(nullptr);
  } else {
    if (!mUserHandleCachedObj) {
      mUserHandleCachedObj = mUserHandle.ToArrayBuffer(aCx);
      if (!mUserHandleCachedObj) {
        aRv.NoteJSContextException(aCx);
        return;
      }
    }
    aRetVal.set(mUserHandleCachedObj);
    aValue.set(mUserHandleCachedObj);
  }
}

+6 −4
Original line number Diff line number Diff line
@@ -32,16 +32,18 @@ class AuthenticatorAssertionResponse final : public AuthenticatorResponse {
  virtual JSObject* WrapObject(JSContext* aCx,
                               JS::Handle<JSObject*> aGivenProto) override;

  void GetAuthenticatorData(JSContext* aCx,
                            JS::MutableHandle<JSObject*> aRetVal);
  void GetAuthenticatorData(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
                            ErrorResult& aRv);

  nsresult SetAuthenticatorData(CryptoBuffer& aBuffer);

  void GetSignature(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal);
  void GetSignature(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
                    ErrorResult& aRv);

  nsresult SetSignature(CryptoBuffer& aBuffer);

  void GetUserHandle(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal);
  void GetUserHandle(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
                     ErrorResult& aRv);

  nsresult SetUserHandle(CryptoBuffer& aUserHandle);

+6 −2
Original line number Diff line number Diff line
@@ -51,11 +51,15 @@ JSObject* AuthenticatorAttestationResponse::WrapObject(
}

void AuthenticatorAttestationResponse::GetAttestationObject(
    JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
    JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
  if (!mAttestationObjectCachedObj) {
    mAttestationObjectCachedObj = mAttestationObject.ToArrayBuffer(aCx);
    if (!mAttestationObjectCachedObj) {
      aRv.NoteJSContextException(aCx);
      return;
    }
  }
  aRetVal.set(mAttestationObjectCachedObj);
  aValue.set(mAttestationObjectCachedObj);
}

nsresult AuthenticatorAttestationResponse::SetAttestationObject(
+2 −2
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ class AuthenticatorAttestationResponse final : public AuthenticatorResponse {
  virtual JSObject* WrapObject(JSContext* aCx,
                               JS::Handle<JSObject*> aGivenProto) override;

  void GetAttestationObject(JSContext* aCx,
                            JS::MutableHandle<JSObject*> aRetVal);
  void GetAttestationObject(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
                            ErrorResult& aRv);

  nsresult SetAttestationObject(CryptoBuffer& aBuffer);

+6 −2
Original line number Diff line number Diff line
@@ -34,11 +34,15 @@ AuthenticatorResponse::~AuthenticatorResponse() {
nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; }

void AuthenticatorResponse::GetClientDataJSON(
    JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
    JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
  if (!mClientDataJSONCachedObj) {
    mClientDataJSONCachedObj = mClientDataJSON.ToArrayBuffer(aCx);
    if (!mClientDataJSONCachedObj) {
      aRv.NoteJSContextException(aCx);
      return;
    }
  }
  aRetVal.set(mClientDataJSONCachedObj);
  aValue.set(mClientDataJSONCachedObj);
}

nsresult AuthenticatorResponse::SetClientDataJSON(CryptoBuffer& aBuffer) {
Loading