<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/urlmon_bind_status_callback.h"

#include <shlguid.h>

#include "base/logging.h"
#include "base/string_util.h"

CFUrlmonBindStatusCallback::CFUrlmonBindStatusCallback()
    : only_buffer_(false), data_(new RequestData()) {
  DLOG(INFO) << __FUNCTION__ << me();
}

CFUrlmonBindStatusCallback::~CFUrlmonBindStatusCallback() {
  DLOG(INFO) << __FUNCTION__ << me();
}

std::string CFUrlmonBindStatusCallback::me() {
  return StringPrintf(" obj=0x%08X",
      static_cast<CFUrlmonBindStatusCallback*>(this));
}

HRESULT CFUrlmonBindStatusCallback::DelegateQI(void* obj, REFIID iid,
                                               void** ret, DWORD cookie) {
  CFUrlmonBindStatusCallback* me =
      reinterpret_cast<CFUrlmonBindStatusCallback*>(obj);
  HRESULT hr = me->delegate_.QueryInterface(iid, ret);
  return hr;
}

HRESULT CFUrlmonBindStatusCallback::Initialize(IBindCtx* bind_ctx,
                                               RequestHeaders* headers) {
  DLOG(INFO) << __FUNCTION__ << me();
  DCHECK(bind_ctx);
  DCHECK(!binding_delegate_.get());
  // headers may be NULL.

  data_->Initialize(headers);

  bind_ctx_ = bind_ctx;

  // Replace the bind context callback with ours.
  HRESULT hr = ::RegisterBindStatusCallback(bind_ctx, this,
                                            delegate_.Receive(), 0);
  if (!delegate_) {
    NOTREACHED();
    hr = E_UNEXPECTED;
  }

  return hr;
}

HRESULT CFUrlmonBindStatusCallback::QueryService(REFGUID service, REFIID iid,
                                                 void** object) {
  HRESULT hr = E_NOINTERFACE;
  if (delegate_) {
    ScopedComPtr<IServiceProvider> svc;
    svc.QueryFrom(delegate_);
    if (svc) {
      hr = svc->QueryService(service, iid, object);
    }
  }
  return hr;
}<commit_msg>Fix a ChromeFrame crash in the bind status callback which occurs due to a NULL delegate pointer being dereferenced. It appears that there are cases where the IMoniker::BindToObject function is called with a bind context without a registered callback. In this case we should not do anything.<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/urlmon_bind_status_callback.h"

#include <shlguid.h>

#include "base/logging.h"
#include "base/string_util.h"

CFUrlmonBindStatusCallback::CFUrlmonBindStatusCallback()
    : only_buffer_(false), data_(new RequestData()) {
  DLOG(INFO) << __FUNCTION__ << me();
}

CFUrlmonBindStatusCallback::~CFUrlmonBindStatusCallback() {
  DLOG(INFO) << __FUNCTION__ << me();
}

std::string CFUrlmonBindStatusCallback::me() {
  return StringPrintf(" obj=0x%08X",
      static_cast<CFUrlmonBindStatusCallback*>(this));
}

HRESULT CFUrlmonBindStatusCallback::DelegateQI(void* obj, REFIID iid,
                                               void** ret, DWORD cookie) {
  CFUrlmonBindStatusCallback* me =
      reinterpret_cast<CFUrlmonBindStatusCallback*>(obj);
  HRESULT hr = me->delegate_.QueryInterface(iid, ret);
  return hr;
}

HRESULT CFUrlmonBindStatusCallback::Initialize(IBindCtx* bind_ctx,
                                               RequestHeaders* headers) {
  DLOG(INFO) << __FUNCTION__ << me();
  DCHECK(bind_ctx);
  DCHECK(!binding_delegate_.get());
  // headers may be NULL.

  data_->Initialize(headers);

  bind_ctx_ = bind_ctx;

  // Replace the bind context callback with ours.
  HRESULT hr = ::RegisterBindStatusCallback(bind_ctx, this,
                                            delegate_.Receive(), 0);
  if (!delegate_) {
    NOTREACHED() << "Failed to find registered bind status callback";
    ::RevokeBindStatusCallback(bind_ctx_, this);
    bind_ctx_.Release();
    hr = E_UNEXPECTED;
  }

  return hr;
}

HRESULT CFUrlmonBindStatusCallback::QueryService(REFGUID service, REFIID iid,
                                                 void** object) {
  HRESULT hr = E_NOINTERFACE;
  if (delegate_) {
    ScopedComPtr<IServiceProvider> svc;
    svc.QueryFrom(delegate_);
    if (svc) {
      hr = svc->QueryService(service, iid, object);
    }
  }
  return hr;
}
{'fraction_non_alphanumeric': 0.10716755012675731, 'fraction_numerical': 0.0036874855957593914, 'mean_word_length': 3.173076923076923, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5384926', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1272, 'n_words': 320}