ftplistparser: follow-up cleanup to remove PL_ERROR()

This commit is contained in:
Daniel Stenberg 2017-10-25 18:19:44 +02:00
parent f786d1f143
commit 1d72b5b891
1 changed files with 78 additions and 89 deletions

View File

@ -264,16 +264,6 @@ static int ftp_pl_get_permission(const char *str)
return permissions; return permissions;
} }
static void PL_ERROR(struct connectdata *conn, CURLcode err)
{
struct ftp_wc_tmpdata *tmpdata = conn->data->wildcard.tmp;
struct ftp_parselist_data *parser = tmpdata->parser;
if(parser->file_data)
Curl_fileinfo_dtor(NULL, parser->file_data);
parser->file_data = NULL;
parser->error = err;
}
static CURLcode ftp_pl_insert_finfo(struct connectdata *conn, static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
struct fileinfo *infop) struct fileinfo *infop)
{ {
@ -347,7 +337,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
* 3. (last) call => is skipped RIGHT HERE and the error is hadled later * 3. (last) call => is skipped RIGHT HERE and the error is hadled later
* in wc_statemach() * in wc_statemach()
*/ */
goto EXIT_LABEL; goto fail;
} }
if(parser->os_type == OS_TYPE_UNKNOWN && bufflen > 0) { if(parser->os_type == OS_TYPE_UNKNOWN && bufflen > 0) {
@ -363,12 +353,12 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->file_data = Curl_fileinfo_alloc(); parser->file_data = Curl_fileinfo_alloc();
if(!parser->file_data) { if(!parser->file_data) {
parser->error = CURLE_OUT_OF_MEMORY; parser->error = CURLE_OUT_OF_MEMORY;
goto EXIT_LABEL; goto fail;
} }
parser->file_data->info.b_data = malloc(FTP_BUFFER_ALLOCSIZE); parser->file_data->info.b_data = malloc(FTP_BUFFER_ALLOCSIZE);
if(!parser->file_data->info.b_data) { if(!parser->file_data->info.b_data) {
PL_ERROR(conn, CURLE_OUT_OF_MEMORY); parser->error = CURLE_OUT_OF_MEMORY;
goto EXIT_LABEL; goto fail;
} }
parser->file_data->info.b_size = FTP_BUFFER_ALLOCSIZE; parser->file_data->info.b_size = FTP_BUFFER_ALLOCSIZE;
parser->item_offset = 0; parser->item_offset = 0;
@ -391,8 +381,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
Curl_fileinfo_dtor(NULL, parser->file_data); Curl_fileinfo_dtor(NULL, parser->file_data);
parser->file_data = NULL; parser->file_data = NULL;
parser->error = CURLE_OUT_OF_MEMORY; parser->error = CURLE_OUT_OF_MEMORY;
PL_ERROR(conn, CURLE_OUT_OF_MEMORY); goto fail;
goto EXIT_LABEL;
} }
} }
@ -430,15 +419,15 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
while(ISDIGIT(*endptr)) while(ISDIGIT(*endptr))
endptr++; endptr++;
if(*endptr != 0) { if(*endptr != 0) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
parser->state.UNIX.main = PL_UNIX_FILETYPE; parser->state.UNIX.main = PL_UNIX_FILETYPE;
finfo->b_used = 0; finfo->b_used = 0;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -471,8 +460,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
finfo->filetype = CURLFILETYPE_DOOR; finfo->filetype = CURLFILETYPE_DOOR;
break; break;
default: default:
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
parser->state.UNIX.main = PL_UNIX_PERMISSION; parser->state.UNIX.main = PL_UNIX_PERMISSION;
parser->item_length = 0; parser->item_length = 0;
@ -482,21 +471,21 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length++; parser->item_length++;
if(parser->item_length <= 9) { if(parser->item_length <= 9) {
if(!strchr("rwx-tTsS", c)) { if(!strchr("rwx-tTsS", c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
else if(parser->item_length == 10) { else if(parser->item_length == 10) {
unsigned int perm; unsigned int perm;
if(c != ' ') { if(c != ' ') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
finfo->b_data[10] = 0; /* terminate permissions */ finfo->b_data[10] = 0; /* terminate permissions */
perm = ftp_pl_get_permission(finfo->b_data + parser->item_offset); perm = ftp_pl_get_permission(finfo->b_data + parser->item_offset);
if(perm & FTP_LP_MALFORMATED_PERM) { if(perm & FTP_LP_MALFORMATED_PERM) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_PERM; parser->file_data->info.flags |= CURLFINFOFLAG_KNOWN_PERM;
parser->file_data->info.perm = perm; parser->file_data->info.perm = perm;
@ -517,8 +506,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.hlinks = PL_UNIX_HLINKS_NUMBER; parser->state.UNIX.sub.hlinks = PL_UNIX_HLINKS_NUMBER;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -539,8 +528,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.user = PL_UNIX_USER_PRESPACE; parser->state.UNIX.sub.user = PL_UNIX_USER_PRESPACE;
} }
else if(c < '0' || c > '9') { else if(c < '0' || c > '9') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -599,8 +588,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.size = PL_UNIX_SIZE_NUMBER; parser->state.UNIX.sub.size = PL_UNIX_SIZE_NUMBER;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -624,8 +613,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
} }
} }
else if(!ISDIGIT(c)) { else if(!ISDIGIT(c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -640,8 +629,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART1; parser->state.UNIX.sub.time = PL_UNIX_TIME_PART1;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -651,8 +640,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART2; parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART2;
} }
else if(!ISALNUM(c) && c != '.') { else if(!ISALNUM(c) && c != '.') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
case PL_UNIX_TIME_PREPART2: case PL_UNIX_TIME_PREPART2:
@ -662,8 +651,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART2; parser->state.UNIX.sub.time = PL_UNIX_TIME_PART2;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -673,8 +662,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART3; parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART3;
} }
else if(!ISALNUM(c) && c != '.') { else if(!ISALNUM(c) && c != '.') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
case PL_UNIX_TIME_PREPART3: case PL_UNIX_TIME_PREPART3:
@ -684,8 +673,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.time = PL_UNIX_TIME_PART3; parser->state.UNIX.sub.time = PL_UNIX_TIME_PART3;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -709,8 +698,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
} }
} }
else if(!ISALNUM(c) && c != '.' && c != ':') { else if(!ISALNUM(c) && c != '.' && c != ':') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -735,8 +724,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_FILETYPE; parser->state.UNIX.main = PL_UNIX_FILETYPE;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
} }
break; break;
@ -747,13 +736,13 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_FILETYPE; parser->state.UNIX.main = PL_UNIX_FILETYPE;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -773,8 +762,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET1; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET1;
} }
else if(c == '\r' || c == '\n') { else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
case PL_UNIX_SYMLINK_PRETARGET1: case PL_UNIX_SYMLINK_PRETARGET1:
@ -783,8 +772,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET2; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET2;
} }
else if(c == '\r' || c == '\n') { else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
else { else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@ -796,8 +785,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET3; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_PRETARGET3;
} }
else if(c == '\r' || c == '\n') { else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
else { else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@ -814,8 +803,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_offset = 0; parser->item_offset = 0;
} }
else if(c == '\r' || c == '\n') { else if(c == '\r' || c == '\n') {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
else { else {
parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME; parser->state.UNIX.sub.symlink = PL_UNIX_SYMLINK_NAME;
@ -828,8 +817,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length = 1; parser->item_length = 1;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
case PL_UNIX_SYMLINK_TARGET: case PL_UNIX_SYMLINK_TARGET:
@ -842,8 +831,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.symlink_target = parser->item_offset; parser->offsets.symlink_target = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
parser->state.UNIX.main = PL_UNIX_FILETYPE; parser->state.UNIX.main = PL_UNIX_FILETYPE;
} }
@ -854,14 +843,14 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.symlink_target = parser->item_offset; parser->offsets.symlink_target = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
parser->state.UNIX.main = PL_UNIX_FILETYPE; parser->state.UNIX.main = PL_UNIX_FILETYPE;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -874,8 +863,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length++; parser->item_length++;
if(parser->item_length < 9) { if(parser->item_length < 9) {
if(!strchr("0123456789-", c)) { /* only simple control */ if(!strchr("0123456789-", c)) { /* only simple control */
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
else if(parser->item_length == 9) { else if(parser->item_length == 9) {
@ -884,13 +873,13 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.NT.sub.time = PL_WINNT_TIME_PRESPACE; parser->state.NT.sub.time = PL_WINNT_TIME_PRESPACE;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
case PL_WINNT_TIME: case PL_WINNT_TIME:
@ -910,8 +899,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->item_length = 0; parser->item_length = 0;
} }
else if(!strchr("APM0123456789:", c)) { else if(!strchr("APM0123456789:", c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -941,8 +930,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
if(curlx_strtoofft(finfo->b_data + if(curlx_strtoofft(finfo->b_data +
parser->item_offset, parser->item_offset,
&endptr, 10, &finfo->size)) { &endptr, 10, &finfo->size)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
/* correct file type */ /* correct file type */
parser->file_data->info.filetype = CURLFILETYPE_FILE; parser->file_data->info.filetype = CURLFILETYPE_FILE;
@ -977,8 +966,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.filename = parser->item_offset; parser->offsets.filename = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
parser->state.NT.main = PL_WINNT_DATE; parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE; parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
@ -989,15 +978,15 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->offsets.filename = parser->item_offset; parser->offsets.filename = parser->item_offset;
result = ftp_pl_insert_finfo(conn, infop); result = ftp_pl_insert_finfo(conn, infop);
if(result) { if(result) {
PL_ERROR(conn, result); parser->error = result;
goto EXIT_LABEL; goto fail;
} }
parser->state.NT.main = PL_WINNT_DATE; parser->state.NT.main = PL_WINNT_DATE;
parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE; parser->state.NT.sub.filename = PL_WINNT_FILENAME_PRESPACE;
} }
else { else {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); parser->error = CURLE_FTP_BAD_FILE_LIST;
goto EXIT_LABEL; goto fail;
} }
break; break;
} }
@ -1006,16 +995,16 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
break; break;
default: default:
retsize = bufflen + 1; retsize = bufflen + 1;
goto EXIT_LABEL; goto fail;
} }
i++; i++;
} }
EXIT_LABEL: fail:
/* Clean up any allocated memory. */ /* Clean up any allocated memory. */
if(parser->file_data != NULL) { if(parser->file_data) {
Curl_fileinfo_dtor(NULL, parser->file_data); Curl_fileinfo_dtor(NULL, parser->file_data);
parser->file_data = NULL; parser->file_data = NULL;
} }