fix: CDUP to handle error when the directory is the root directory

This commit is contained in:
Ugo
2025-07-19 14:45:02 +01:00
parent f65d8d20f6
commit 3b69b5e062
3 changed files with 23 additions and 7 deletions

View File

@ -444,7 +444,7 @@ int parseCommandProt(ftpDataType *data, int socketId)
int parseCommandCcc(ftpDataType *data, int socketId)
{
int returnCode;
int returnCode;
#ifdef OPENSSL_ENABLED
if (!data->clients[socketId].tlsIsEnabled) {
@ -457,7 +457,6 @@ int parseCommandCcc(ftpDataType *data, int socketId)
}
returnCode = socketPrintf(data, socketId, "s", "200 Control connection switched to plaintext\r\n");
if (returnCode <= 0)
{
LOG_ERROR("socketPrintfError");
@ -470,7 +469,6 @@ int parseCommandCcc(ftpDataType *data, int socketId)
#ifndef OPENSSL_ENABLED
returnCode = socketPrintf(data, socketId, "s", "502 Command not supported\r\n");
if (returnCode <= 0)
{
LOG_ERROR("socketPrintfError");
@ -2102,8 +2100,8 @@ int parseCommandCdup(ftpDataType *data, int socketId)
{
int returnCode;
FILE_DirectoryToParent(&data->clients[socketId].login.absolutePath.text, &data->clients[socketId].memoryTable);
FILE_DirectoryToParent(&data->clients[socketId].login.ftpPath.text, &data->clients[socketId].memoryTable);
returnCode = FILE_DirectoryToParent(&data->clients[socketId].login.absolutePath.text, &data->clients[socketId].memoryTable);
returnCode = FILE_DirectoryToParent(&data->clients[socketId].login.ftpPath.text, &data->clients[socketId].memoryTable);
data->clients[socketId].login.absolutePath.textLen = strlen(data->clients[socketId].login.absolutePath.text);
data->clients[socketId].login.ftpPath.textLen = strlen(data->clients[socketId].login.ftpPath.text);
@ -2112,6 +2110,18 @@ int parseCommandCdup(ftpDataType *data, int socketId)
setDynamicStringDataType(&data->clients[socketId].login.absolutePath, data->clients[socketId].login.homePath.text, data->clients[socketId].login.homePath.textLen, &data->clients[socketId].memoryTable);
}
if (!returnCode)
{
returnCode = socketPrintf(data, socketId, "sss", "550 Already at root directory. ", data->clients[socketId].login.ftpPath.text, "\r\n");
if (returnCode <= 0)
{
LOG_ERROR("socketPrintfError");
return FTP_COMMAND_PROCESSED_WRITE_ERROR;
}
return FTP_COMMAND_PROCESSED;
}
returnCode = socketPrintf(data, socketId, "sss", "250 OK. Current directory is ", data->clients[socketId].login.ftpPath.text, "\r\n");
if (returnCode <= 0)

View File

@ -781,7 +781,7 @@ void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTab
(*sourceString)[theNewSize] = '\0';
}
void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable)
int FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable)
{
//my_printf("\n");
@ -802,6 +802,10 @@ void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType **
}
//my_printf("\n theLastSlash = %d", theLastSlash);
if (theLastSlash == 0 && strLen == 1)
{
return 0;
}
if (theLastSlash > -1)
{
@ -818,6 +822,8 @@ void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType **
//my_printf("\nThe directory upped is = %s", (*sourceString));
}
return 1;
}
int FILE_LockFile(int fd)

View File

@ -74,7 +74,7 @@
void FILE_AppendStringToFile(char *fileName, char *theString);
time_t FILE_GetLastModifiedData(char *path);
void FILE_AppendToString(char ** sourceString, char *theString, DYNMEM_MemoryTable_DataType ** memoryTable);
void FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable);
int FILE_DirectoryToParent(char ** sourceString, DYNMEM_MemoryTable_DataType ** memoryTable);
int FILE_LockFile(int fd);
int FILE_doChownFromUidGidString(const char *file_path, const char *user_name, const char *group_name);
int FILE_doChownFromUidGid(const char *file_path, uid_t uid, gid_t gid);