struct curl_fileinfo *finfo;
unsigned long i = 0;
CURLcode result;
+ size_t retsize = bufflen;
if(parser->error) { /* error in previous call */
/* scenario:
* 3. (last) call => is skipped RIGHT HERE and the error is hadled later
* in wc_statemach()
*/
- return bufflen;
+ goto EXIT_LABEL;
}
if(parser->os_type == OS_TYPE_UNKNOWN && bufflen > 0) {
parser->file_data = Curl_fileinfo_alloc();
if(!parser->file_data) {
parser->error = CURLE_OUT_OF_MEMORY;
- return bufflen;
+ goto EXIT_LABEL;
}
parser->file_data->info.b_data = malloc(FTP_BUFFER_ALLOCSIZE);
if(!parser->file_data->info.b_data) {
PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->file_data->info.b_size = FTP_BUFFER_ALLOCSIZE;
parser->item_offset = 0;
parser->file_data = NULL;
parser->error = CURLE_OUT_OF_MEMORY;
PL_ERROR(conn, CURLE_OUT_OF_MEMORY);
- return bufflen;
+ goto EXIT_LABEL;
}
}
endptr++;
if(*endptr != 0) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
finfo->b_used = 0;
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
break;
default:
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.UNIX.main = PL_UNIX_PERMISSION;
parser->item_length = 0;
if(parser->item_length <= 9) {
if(!strchr("rwx-tTsS", c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
else if(parser->item_length == 10) {
unsigned int perm;
if(c != ' ') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
finfo->b_data[10] = 0; /* terminate permissions */
perm = ftp_pl_get_permission(finfo->b_data + parser->item_offset);
if(perm & FTP_LP_MALFORMATED_PERM) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_PERM;
parser->file_data->info.perm = perm;
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
}
else if(c < '0' || c > '9') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
}
else if(!ISDIGIT(c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
}
else if(!ISALNUM(c) && c != '.') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
case PL_UNIX_TIME_PREPART2:
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
}
else if(!ISALNUM(c) && c != '.') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
case PL_UNIX_TIME_PREPART3:
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
}
else if(!ISALNUM(c) && c != '.' && c != ':') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
}
break;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
}
else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
case PL_UNIX_SYMLINK_PRETARGET1:
}
else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
}
else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
}
else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
case PL_UNIX_SYMLINK_TARGET:
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
}
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.UNIX.main = PL_UNIX_FILETYPE;
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
if(parser->item_length < 9) {
if(!strchr("0123456789-", c)) { /* only simple control */
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
else if(parser->item_length == 9) {
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
case PL_WINNT_TIME:
}
else if(!strchr("APM0123456789:", c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
parser->item_offset,
&endptr, 10, &finfo->size)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
/* correct file type */
parser->file_data->info.filetype = CURLFILETYPE_FILE;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
result = ftp_pl_insert_finfo(conn, infop);
if(result) {
PL_ERROR(conn, result);
- return bufflen;
+ goto EXIT_LABEL;
}
parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
}
else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
- return bufflen;
+ goto EXIT_LABEL;
}
break;
}
}
break;
default:
- return bufflen + 1;
+ retsize = bufflen + 1;
+ goto EXIT_LABEL;
}
i++;
}
- return bufflen;
+EXIT_LABEL:
+
+ /* Clean up any allocated memory. */
+ if(parser->file_data != NULL) {
+ Curl_fileinfo_dtor(NULL, parser->file_data);
+ parser->file_data = NULL;
+ }
+
+ return retsize;
}
#endif /* CURL_DISABLE_FTP */