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

Side by Side Diff: net/ftp/ftp_directory_listing_buffer.cc

Issue 2846037: Fix a renderer crash while processing FTP directory listing. (Closed)
Patch Set: Created 10 years, 5 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/ftp/ftp_directory_listing_buffer.h" 5 #include "net/ftp/ftp_directory_listing_buffer.h"
6 6
7 #include "base/i18n/icu_encoding_detection.h" 7 #include "base/i18n/icu_encoding_detection.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 buffer_.erase(0, cut_pos); 109 buffer_.erase(0, cut_pos);
110 return OK; 110 return OK;
111 } 111 }
112 112
113 int FtpDirectoryListingBuffer::ParseLines() { 113 int FtpDirectoryListingBuffer::ParseLines() {
114 while (!lines_.empty()) { 114 while (!lines_.empty()) {
115 string16 line = lines_.front(); 115 string16 line = lines_.front();
116 lines_.pop_front(); 116 lines_.pop_front();
117 if (current_parser_) { 117 if (current_parser_) {
118 if (!current_parser_->ConsumeLine(line)) 118 if (!current_parser_->ConsumeLine(line))
119 return ERR_FAILED; 119 return ERR_FAILED;
wtc 2010/06/26 17:44:37 Should we return ERR_UNRECOGNIZED_FTP_DIRECTORY_LI
Paweł Hajdan Jr. 2010/06/28 16:58:49 Indeed, getting rid of ERR_FAILED would be good. I
wtc 2010/06/30 15:07:53 Adding ERR_INVALID_FTP_DIRECTORY_LISTING_FORMAT is
120 } else { 120 } else {
121 ParserSet::iterator i = parsers_.begin(); 121 ParserSet::iterator i = parsers_.begin();
122 while (i != parsers_.end()) { 122 while (i != parsers_.end()) {
123 if ((*i)->ConsumeLine(line)) { 123 if ((*i)->ConsumeLine(line)) {
124 i++; 124 i++;
125 } else { 125 } else {
126 delete *i; 126 delete *i;
127 parsers_.erase(i++); 127 parsers_.erase(i++);
128 } 128 }
129 } 129 }
130 if (parsers_.empty()) 130 if (parsers_.empty())
131 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; 131 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT;
132 if (parsers_.size() == 1) 132 if (parsers_.size() == 1)
133 current_parser_ = *parsers_.begin(); 133 current_parser_ = *parsers_.begin();
134 } 134 }
135 } 135 }
136 136
137 return OK; 137 return OK;
138 } 138 }
139 139
140 int FtpDirectoryListingBuffer::OnEndOfInput() { 140 int FtpDirectoryListingBuffer::OnEndOfInput() {
141 ParserSet::iterator i = parsers_.begin(); 141 ParserSet::iterator i = parsers_.begin();
142 while (i != parsers_.end()) { 142 while (i != parsers_.end()) {
143 if ((*i)->OnEndOfInput()) { 143 if ((*i)->OnEndOfInput()) {
144 i++; 144 i++;
145 } else { 145 } else {
146 delete *i; 146 delete *i;
wtc 2010/06/26 17:44:37 You can also fix this bug by adding the following
Paweł Hajdan Jr. 2010/06/28 16:58:49 Sounds good to me.
147 parsers_.erase(i++); 147 parsers_.erase(i++);
148 } 148 }
149 } 149 }
150 150
151 if (parsers_.size() != 1) { 151 if (parsers_.size() != 1) {
152 DCHECK(!current_parser_); 152 current_parser_ = NULL;
153 153
154 // We may hit an ambiguity in case of listings which have no entries. That's 154 // We may hit an ambiguity in case of listings which have no entries. That's
155 // fine, as long as all remaining parsers agree that the listing is empty. 155 // fine, as long as all remaining parsers agree that the listing is empty.
156 bool all_listings_empty = true; 156 bool all_listings_empty = true;
157 for (ParserSet::iterator i = parsers_.begin(); i != parsers_.end(); ++i) { 157 for (ParserSet::iterator i = parsers_.begin(); i != parsers_.end(); ++i) {
158 if ((*i)->EntryAvailable()) 158 if ((*i)->EntryAvailable())
159 all_listings_empty = false; 159 all_listings_empty = false;
160 } 160 }
161 if (all_listings_empty) 161 if (all_listings_empty)
162 return OK; 162 return OK;
163 163
164 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; 164 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT;
165 } 165 }
166 166
167 current_parser_ = *parsers_.begin(); 167 current_parser_ = *parsers_.begin();
168 return OK; 168 return OK;
169 } 169 }
170 170
171 } // namespace net 171 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698