Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Side by Side Diff: chrome/browser/webdata/web_database.cc

Issue 1789001: AutoFill crash in CreditCard::SetInfo(). (Closed)
Patch Set: Virtual back to original. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/webdata/web_database.h" 5 #include "chrome/browser/webdata/web_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 return false; 1542 return false;
1543 } 1543 }
1544 1544
1545 s.BindInt(0, profile_id); 1545 s.BindInt(0, profile_id);
1546 if (s.Step()) 1546 if (s.Step())
1547 *profile = AutoFillProfileFromStatement(s); 1547 *profile = AutoFillProfileFromStatement(s);
1548 1548
1549 return s.Succeeded(); 1549 return s.Succeeded();
1550 } 1550 }
1551 1551
1552 static void BindCreditCardToStatement(const CreditCard& creditcard, 1552 static void BindCreditCardToStatement(const CreditCard& credit_card,
1553 sql::Statement* s) { 1553 sql::Statement* s) {
1554 s->BindString(0, UTF16ToUTF8(creditcard.Label())); 1554 s->BindString(0, UTF16ToUTF8(credit_card.Label()));
1555 s->BindInt(1, creditcard.unique_id()); 1555 s->BindInt(1, credit_card.unique_id());
1556 1556
1557 string16 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NAME)); 1557 string16 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NAME));
1558 s->BindString(2, UTF16ToUTF8(text)); 1558 s->BindString(2, UTF16ToUTF8(text));
1559 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_TYPE)); 1559 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_TYPE));
1560 s->BindString(3, UTF16ToUTF8(text)); 1560 s->BindString(3, UTF16ToUTF8(text));
1561 text.clear(); // No unencrypted cc info. 1561 text.clear(); // No unencrypted cc info.
1562 s->BindString(4, UTF16ToUTF8(text)); 1562 s->BindString(4, UTF16ToUTF8(text));
1563 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH)); 1563 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_MONTH));
1564 s->BindString(5, UTF16ToUTF8(text)); 1564 s->BindString(5, UTF16ToUTF8(text));
1565 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 1565 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1566 s->BindString(6, UTF16ToUTF8(text)); 1566 s->BindString(6, UTF16ToUTF8(text));
1567 text.clear(); 1567 text.clear();
1568 s->BindString(7, UTF16ToUTF8(text)); 1568 s->BindString(7, UTF16ToUTF8(text));
1569 s->BindString(8, UTF16ToUTF8(creditcard.billing_address())); 1569 s->BindString(8, UTF16ToUTF8(credit_card.billing_address()));
1570 s->BindString(9, UTF16ToUTF8(creditcard.shipping_address())); 1570 s->BindString(9, UTF16ToUTF8(credit_card.shipping_address()));
1571 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER)); 1571 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_NUMBER));
1572 std::string encrypted_data; 1572 std::string encrypted_data;
1573 Encryptor::EncryptString16(text, &encrypted_data); 1573 Encryptor::EncryptString16(text, &encrypted_data);
1574 s->BindBlob(10, encrypted_data.data(), 1574 s->BindBlob(10, encrypted_data.data(),
1575 static_cast<int>(encrypted_data.length())); 1575 static_cast<int>(encrypted_data.length()));
1576 text = creditcard.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE)); 1576 text = credit_card.GetFieldText(AutoFillType(CREDIT_CARD_VERIFICATION_CODE));
1577 Encryptor::EncryptString16(text, &encrypted_data); 1577 Encryptor::EncryptString16(text, &encrypted_data);
1578 s->BindBlob(11, encrypted_data.data(), 1578 s->BindBlob(11, encrypted_data.data(),
1579 static_cast<int>(encrypted_data.length())); 1579 static_cast<int>(encrypted_data.length()));
1580 } 1580 }
1581 1581
1582 bool WebDatabase::AddCreditCard(const CreditCard& creditcard) { 1582 bool WebDatabase::AddCreditCard(const CreditCard& credit_card) {
1583 sql::Statement s(db_.GetUniqueStatement( 1583 sql::Statement s(db_.GetUniqueStatement(
1584 "INSERT INTO credit_cards" 1584 "INSERT INTO credit_cards"
1585 "(label, unique_id, name_on_card, type, card_number," 1585 "(label, unique_id, name_on_card, type, card_number,"
1586 " expiration_month, expiration_year, verification_code, billing_address," 1586 " expiration_month, expiration_year, verification_code, billing_address,"
1587 " shipping_address, card_number_encrypted, verification_code_encrypted)" 1587 " shipping_address, card_number_encrypted, verification_code_encrypted)"
1588 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)")); 1588 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"));
1589 if (!s) { 1589 if (!s) {
1590 NOTREACHED() << "Statement prepare failed"; 1590 NOTREACHED() << "Statement prepare failed";
1591 return false; 1591 return false;
1592 } 1592 }
1593 1593
1594 BindCreditCardToStatement(creditcard, &s); 1594 BindCreditCardToStatement(credit_card, &s);
1595 1595
1596 if (!s.Run()) { 1596 if (!s.Run()) {
1597 NOTREACHED(); 1597 NOTREACHED();
1598 return false; 1598 return false;
1599 } 1599 }
1600 1600
1601 DCHECK_GT(db_.GetLastChangeCount(), 0); 1601 DCHECK_GT(db_.GetLastChangeCount(), 0);
1602 return s.Succeeded(); 1602 return s.Succeeded();
1603 } 1603 }
1604 1604
1605 static CreditCard* CreditCardFromStatement(const sql::Statement& s) { 1605 static CreditCard* CreditCardFromStatement(const sql::Statement& s) {
1606 CreditCard* creditcard = new CreditCard( 1606 CreditCard* credit_card = new CreditCard(
1607 UTF8ToUTF16(s.ColumnString(0)), s.ColumnInt(1)); 1607 UTF8ToUTF16(s.ColumnString(0)), s.ColumnInt(1));
1608 creditcard->SetInfo(AutoFillType(CREDIT_CARD_NAME), 1608 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NAME),
1609 UTF8ToUTF16(s.ColumnString(2))); 1609 UTF8ToUTF16(s.ColumnString(2)));
1610 creditcard->SetInfo(AutoFillType(CREDIT_CARD_TYPE), 1610 credit_card->SetInfo(AutoFillType(CREDIT_CARD_TYPE),
1611 UTF8ToUTF16(s.ColumnString(3))); 1611 UTF8ToUTF16(s.ColumnString(3)));
1612 string16 credit_card_number = UTF8ToUTF16(s.ColumnString(4)); 1612 string16 credit_card_number = UTF8ToUTF16(s.ColumnString(4));
1613 // It could be non-empty prior to version 23. After that it encrypted in 1613 // It could be non-empty prior to version 23. After that it encrypted in
1614 // the column 10. 1614 // the column 10.
1615 if (credit_card_number.empty()) { 1615 if (credit_card_number.empty()) {
1616 int encrypted_cc_len = s.ColumnByteLength(10); 1616 int encrypted_cc_len = s.ColumnByteLength(10);
1617 std::string encrypted_cc; 1617 std::string encrypted_cc;
1618 if (encrypted_cc_len) { 1618 if (encrypted_cc_len) {
1619 encrypted_cc.resize(encrypted_cc_len); 1619 encrypted_cc.resize(encrypted_cc_len);
1620 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len); 1620 memcpy(&encrypted_cc[0], s.ColumnBlob(10), encrypted_cc_len);
1621 Encryptor::DecryptString16(encrypted_cc, &credit_card_number); 1621 Encryptor::DecryptString16(encrypted_cc, &credit_card_number);
1622 } 1622 }
1623 } 1623 }
1624 creditcard->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number); 1624 credit_card->SetInfo(AutoFillType(CREDIT_CARD_NUMBER), credit_card_number);
1625 creditcard->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH), 1625 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_MONTH),
1626 UTF8ToUTF16(s.ColumnString(5))); 1626 UTF8ToUTF16(s.ColumnString(5)));
1627 creditcard->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR), 1627 credit_card->SetInfo(AutoFillType(CREDIT_CARD_EXP_4_DIGIT_YEAR),
1628 UTF8ToUTF16(s.ColumnString(6))); 1628 UTF8ToUTF16(s.ColumnString(6)));
1629 1629
1630 string16 credit_card_verification_code = UTF8ToUTF16(s.ColumnString(7)); 1630 string16 credit_card_verification_code = UTF8ToUTF16(s.ColumnString(7));
1631 // It could be non-empty prior to version 23. After that it encrypted in 1631 // It could be non-empty prior to version 23. After that it encrypted in
1632 // the column 11. 1632 // the column 11.
1633 if (credit_card_verification_code.empty()) { 1633 if (credit_card_verification_code.empty()) {
1634 int encrypted_cc_len = s.ColumnByteLength(11); 1634 int encrypted_cc_len = s.ColumnByteLength(11);
1635 std::string encrypted_cc; 1635 std::string encrypted_cc;
1636 if (encrypted_cc_len) { 1636 if (encrypted_cc_len) {
1637 encrypted_cc.resize(encrypted_cc_len); 1637 encrypted_cc.resize(encrypted_cc_len);
1638 memcpy(&encrypted_cc[0], s.ColumnBlob(11), encrypted_cc_len); 1638 memcpy(&encrypted_cc[0], s.ColumnBlob(11), encrypted_cc_len);
1639 Encryptor::DecryptString16(encrypted_cc, &credit_card_verification_code); 1639 Encryptor::DecryptString16(encrypted_cc, &credit_card_verification_code);
1640 } 1640 }
1641 } 1641 }
1642 creditcard->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE), 1642 credit_card->SetInfo(AutoFillType(CREDIT_CARD_VERIFICATION_CODE),
1643 credit_card_verification_code); 1643 credit_card_verification_code);
1644 creditcard->set_billing_address(UTF8ToUTF16(s.ColumnString(8))); 1644 credit_card->set_billing_address(UTF8ToUTF16(s.ColumnString(8)));
1645 creditcard->set_shipping_address(UTF8ToUTF16(s.ColumnString(9))); 1645 credit_card->set_shipping_address(UTF8ToUTF16(s.ColumnString(9)));
1646 // Column 10 is processed above. 1646 // Column 10 is processed above.
1647 // Column 11 is processed above. 1647 // Column 11 is processed above.
1648 1648
1649 return creditcard; 1649 return credit_card;
1650 } 1650 }
1651 1651
1652 bool WebDatabase::GetCreditCardForLabel(const string16& label, 1652 bool WebDatabase::GetCreditCardForLabel(const string16& label,
1653 CreditCard** creditcard) { 1653 CreditCard** credit_card) {
1654 DCHECK(creditcard); 1654 DCHECK(credit_card);
1655 sql::Statement s(db_.GetUniqueStatement( 1655 sql::Statement s(db_.GetUniqueStatement(
1656 "SELECT * FROM credit_cards " 1656 "SELECT * FROM credit_cards "
1657 "WHERE label = ?")); 1657 "WHERE label = ?"));
1658 if (!s) { 1658 if (!s) {
1659 NOTREACHED() << "Statement prepare failed"; 1659 NOTREACHED() << "Statement prepare failed";
1660 return false; 1660 return false;
1661 } 1661 }
1662 1662
1663 s.BindString(0, UTF16ToUTF8(label)); 1663 s.BindString(0, UTF16ToUTF8(label));
1664 if (!s.Step()) 1664 if (!s.Step())
1665 return false; 1665 return false;
1666 1666
1667 *creditcard = CreditCardFromStatement(s); 1667 *credit_card = CreditCardFromStatement(s);
1668 1668
1669 return s.Succeeded(); 1669 return s.Succeeded();
1670 } 1670 }
1671 1671
1672 bool WebDatabase::GetCreditCardForID(int card_id, CreditCard** card) { 1672 bool WebDatabase::GetCreditCardForID(int credit_card_id,
1673 CreditCard** credit_card) {
1673 sql::Statement s(db_.GetUniqueStatement( 1674 sql::Statement s(db_.GetUniqueStatement(
1674 "SELECT * FROM credit_cards " 1675 "SELECT * FROM credit_cards "
1675 "WHERE unique_id = ?")); 1676 "WHERE unique_id = ?"));
1676 if (!s) { 1677 if (!s) {
1677 NOTREACHED() << "Statement prepare failed"; 1678 NOTREACHED() << "Statement prepare failed";
1678 return false; 1679 return false;
1679 } 1680 }
1680 1681
1681 s.BindInt(0, card_id); 1682 s.BindInt(0, credit_card_id);
1682 if (!s.Step()) 1683 if (!s.Step())
1683 return false; 1684 return false;
1684 1685
1685 *card = CreditCardFromStatement(s); 1686 *credit_card = CreditCardFromStatement(s);
1686 1687
1687 return s.Succeeded(); 1688 return s.Succeeded();
1688 } 1689 }
1689 1690
1690 bool WebDatabase::GetCreditCards( 1691 bool WebDatabase::GetCreditCards(
1691 std::vector<CreditCard*>* creditcards) { 1692 std::vector<CreditCard*>* credit_cards) {
1692 DCHECK(creditcards); 1693 DCHECK(credit_cards);
1693 creditcards->clear(); 1694 credit_cards->clear();
1694 1695
1695 sql::Statement s(db_.GetUniqueStatement("SELECT * FROM credit_cards")); 1696 sql::Statement s(db_.GetUniqueStatement("SELECT * FROM credit_cards"));
1696 if (!s) { 1697 if (!s) {
1697 NOTREACHED() << "Statement prepare failed"; 1698 NOTREACHED() << "Statement prepare failed";
1698 return false; 1699 return false;
1699 } 1700 }
1700 1701
1701 while (s.Step()) 1702 while (s.Step())
1702 creditcards->push_back(CreditCardFromStatement(s)); 1703 credit_cards->push_back(CreditCardFromStatement(s));
1703 1704
1704 return s.Succeeded(); 1705 return s.Succeeded();
1705 } 1706 }
1706 1707
1707 bool WebDatabase::UpdateCreditCard(const CreditCard& creditcard) { 1708 bool WebDatabase::UpdateCreditCard(const CreditCard& credit_card) {
1708 DCHECK(creditcard.unique_id()); 1709 DCHECK(credit_card.unique_id());
1709 sql::Statement s(db_.GetUniqueStatement( 1710 sql::Statement s(db_.GetUniqueStatement(
1710 "UPDATE credit_cards " 1711 "UPDATE credit_cards "
1711 "SET label=?, unique_id=?, name_on_card=?, type=?, card_number=?, " 1712 "SET label=?, unique_id=?, name_on_card=?, type=?, card_number=?, "
1712 " expiration_month=?, expiration_year=?, verification_code=?, " 1713 " expiration_month=?, expiration_year=?, verification_code=?, "
1713 " billing_address=?, shipping_address=?, card_number_encrypted=?, " 1714 " billing_address=?, shipping_address=?, card_number_encrypted=?, "
1714 " verification_code_encrypted=? " 1715 " verification_code_encrypted=? "
1715 "WHERE unique_id=?")); 1716 "WHERE unique_id=?"));
1716 if (!s) { 1717 if (!s) {
1717 NOTREACHED() << "Statement prepare failed"; 1718 NOTREACHED() << "Statement prepare failed";
1718 return false; 1719 return false;
1719 } 1720 }
1720 1721
1721 BindCreditCardToStatement(creditcard, &s); 1722 BindCreditCardToStatement(credit_card, &s);
1722 s.BindInt(12, creditcard.unique_id()); 1723 s.BindInt(12, credit_card.unique_id());
1723 bool result = s.Run(); 1724 bool result = s.Run();
1724 DCHECK_GT(db_.GetLastChangeCount(), 0); 1725 DCHECK_GT(db_.GetLastChangeCount(), 0);
1725 return result; 1726 return result;
1726 } 1727 }
1727 1728
1728 bool WebDatabase::RemoveCreditCard(int creditcard_id) { 1729 bool WebDatabase::RemoveCreditCard(int credit_card_id) {
1729 DCHECK_NE(0, creditcard_id); 1730 DCHECK_NE(0, credit_card_id);
1730 sql::Statement s(db_.GetUniqueStatement( 1731 sql::Statement s(db_.GetUniqueStatement(
1731 "DELETE FROM credit_cards WHERE unique_id = ?")); 1732 "DELETE FROM credit_cards WHERE unique_id = ?"));
1732 if (!s) { 1733 if (!s) {
1733 NOTREACHED() << "Statement prepare failed"; 1734 NOTREACHED() << "Statement prepare failed";
1734 return false; 1735 return false;
1735 } 1736 }
1736 1737
1737 s.BindInt(0, creditcard_id); 1738 s.BindInt(0, credit_card_id);
1738 return s.Run(); 1739 return s.Run();
1739 } 1740 }
1740 1741
1741 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, 1742 bool WebDatabase::AddToCountOfFormElement(int64 pair_id,
1742 int delta, 1743 int delta,
1743 bool* was_removed) { 1744 bool* was_removed) {
1744 DCHECK(was_removed); 1745 DCHECK(was_removed);
1745 int count = 0; 1746 int count = 0;
1746 *was_removed = false; 1747 *was_removed = false;
1747 1748
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 1829
1829 // Add successive versions here. Each should set the version number and 1830 // Add successive versions here. Each should set the version number and
1830 // compatible version number as appropriate, then fall through to the next 1831 // compatible version number as appropriate, then fall through to the next
1831 // case. 1832 // case.
1832 1833
1833 case kCurrentVersionNumber: 1834 case kCurrentVersionNumber:
1834 // No migration needed. 1835 // No migration needed.
1835 return; 1836 return;
1836 } 1837 }
1837 } 1838 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698