Skip to content

Commit

Permalink
Fix MLSD/MLST bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtheall committed Dec 10, 2017
1 parent 7b1176d commit d00b1a8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions source/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,16 @@ ftp_session_fill_dirent_type(ftp_session_t *session, const struct stat *st,
if(session->mlst_flags & SESSION_MLST_MODIFY)
{
/* mtime fact */
struct tm *tm = gmtime(&st->st_mtime);
if(tm == NULL)
return errno;

session->buffersize +=
sprintf(session->buffer + session->buffersize, "Modify=%ld;", st->st_mtime);
strftime(session->buffer + session->buffersize,
sizeof(session->buffer) - session->buffersize,
"Modify=%Y%m%d%H%M%S;", tm);
if(session->buffersize == 0)
return EOVERFLOW;
}

if(session->mlst_flags & SESSION_MLST_PERM)
Expand Down Expand Up @@ -814,8 +822,8 @@ ftp_session_fill_dirent_type(ftp_session_t *session, const struct stat *st,
{
/* unix mode fact */
mode_t mask = S_IRWXU | S_IRWXG | S_IRWXO | S_ISVTX | S_ISGID | S_ISUID;
session->buffersize =
sprintf(session->buffer, "UNIX.mode=0%lo;",
session->buffersize +=
sprintf(session->buffer + session->buffersize, "UNIX.mode=0%lo;",
(unsigned long)(st->st_mode & mask));
}

Expand Down Expand Up @@ -3189,14 +3197,15 @@ FTP_DECLARE(MLST)
return;
}

path = malloc(session->buffersize);
path = malloc(session->buffersize + 1);
if(!path)
{
ftp_send_response(session, 550, "%s\r\n", strerror(ENOMEM));
return;
}

memcpy(path, session->buffer, session->buffersize);
path[session->buffersize] = 0;
ftp_send_response(session, -250, "Status\r\n%s250 End\r\n", path);
free(path);
}
Expand Down

0 comments on commit d00b1a8

Please sign in to comment.