Skip to content

Commit

Permalink
app-layer/ftp: apply clang-tidy
Browse files Browse the repository at this point in the history
Patch generated by clang-tidy.

Most hunks are `else after return` but there is also
an unused parameter removed from FTPDataParse() function.
  • Loading branch information
regit committed Jan 11, 2025
1 parent 124b610 commit 75eb6fb
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/app-layer-ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ uint32_t ftp_max_line_len = 4096;
SC_ATOMIC_DECLARE(uint64_t, ftp_memuse);
SC_ATOMIC_DECLARE(uint64_t, ftp_memcap);

static FTPTransaction *FTPGetOldestTx(const FtpState *, FTPTransaction *);
static FTPTransaction *FTPGetOldestTx(const FtpState * /*ftp_state*/, FTPTransaction * /*starttx*/);

static void FTPParseMemcap(void)
{
Expand Down Expand Up @@ -375,7 +375,8 @@ static AppLayerResult FTPGetLineForDirection(
SCReturnStruct(APP_LAYER_OK);
}
SCReturnStruct(APP_LAYER_INCOMPLETE(input->consumed, input->len + 1));
} else if (*current_line_truncated) {
}
if (*current_line_truncated) {
// Whatever came in with first LF should also get discarded
*current_line_truncated = false;
line->len = 0;
Expand Down Expand Up @@ -507,7 +508,8 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt

if (input == NULL && AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS)) {
SCReturnStruct(APP_LAYER_OK);
} else if (input == NULL || input_len == 0) {
}
if (input == NULL || input_len == 0) {
SCReturnStruct(APP_LAYER_ERROR);
}

Expand All @@ -520,7 +522,8 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt
res = FTPGetLineForDirection(&line, &ftpi, &state->current_line_truncated_ts);
if (res.status == 1) {
return res;
} else if (res.status == -1) {
}
if (res.status == -1) {
break;
}
const FtpCommand *cmd_descriptor;
Expand Down Expand Up @@ -617,11 +620,9 @@ static AppLayerResult FTPParseRequest(Flow *f, void *ftp_state, AppLayerParserSt
FtpTransferCmdFree(data);
SCLogDebug("No expectation created.");
SCReturnStruct(APP_LAYER_ERROR);
} else {
SCLogDebug("Expectation created [direction: %s, dynamic port %"PRIu16"].",
state->active ? "to server" : "to client",
state->dyn_port);
}
SCLogDebug("Expectation created [direction: %s, dynamic port %" PRIu16 "].",
state->active ? "to server" : "to client", state->dyn_port);

/* reset the dyn port to avoid duplicate */
state->dyn_port = 0;
Expand Down Expand Up @@ -713,7 +714,8 @@ static AppLayerResult FTPParseResponse(Flow *f, void *ftp_state, AppLayerParserS
res = FTPGetLineForDirection(&line, &ftpi, &state->current_line_truncated_tc);
if (res.status == 1) {
return res;
} else if (res.status == -1) {
}
if (res.status == -1) {
break;
}
FTPTransaction *tx = FTPGetOldestTx(state, lasttx);
Expand Down Expand Up @@ -929,7 +931,7 @@ static void FTPStateTransactionFree(void *state, uint64_t tx_id)
TAILQ_FOREACH(tx, &ftp_state->tx_list, next) {
if (tx_id < tx->tx_id)
break;
else if (tx_id > tx->tx_id)
if (tx_id > tx->tx_id)
continue;

if (tx == ftp_state->curr_tx)
Expand Down Expand Up @@ -1046,7 +1048,7 @@ static StreamingBufferConfig sbcfg = STREAMING_BUFFER_CONFIG_INITIALIZER;
* \retval 1 when the command is parsed, 0 otherwise
*/
static AppLayerResult FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
AppLayerParserState *pstate, StreamSlice stream_slice, void *local_data, uint8_t direction)
AppLayerParserState *pstate, StreamSlice stream_slice, uint8_t direction)
{
const uint8_t *input = StreamSliceGetData(&stream_slice);
uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
Expand Down Expand Up @@ -1116,10 +1118,8 @@ static AppLayerResult FTPDataParse(Flow *f, FtpDataState *ftpdata_state,

/* open with fixed track_id 0 as we can have just one
* file per ftp-data flow. */
if (FileOpenFileWithId(ftpdata_state->files, &sbcfg,
0ULL, (uint8_t *) ftpdata_state->file_name,
ftpdata_state->file_len,
input, input_len, flags) != 0) {
if (FileOpenFileWithId(ftpdata_state->files, &sbcfg, 0ULL, ftpdata_state->file_name,
ftpdata_state->file_len, input, input_len, flags) != 0) {
SCLogDebug("Can't open file");
ret = -1;
}
Expand Down Expand Up @@ -1171,13 +1171,13 @@ static AppLayerResult FTPDataParse(Flow *f, FtpDataState *ftpdata_state,
static AppLayerResult FTPDataParseRequest(Flow *f, void *ftp_state, AppLayerParserState *pstate,
StreamSlice stream_slice, void *local_data)
{
return FTPDataParse(f, ftp_state, pstate, stream_slice, local_data, STREAM_TOSERVER);
return FTPDataParse(f, ftp_state, pstate, stream_slice, STREAM_TOSERVER);
}

static AppLayerResult FTPDataParseResponse(Flow *f, void *ftp_state, AppLayerParserState *pstate,
StreamSlice stream_slice, void *local_data)
{
return FTPDataParse(f, ftp_state, pstate, stream_slice, local_data, STREAM_TOCLIENT);
return FTPDataParse(f, ftp_state, pstate, stream_slice, STREAM_TOCLIENT);
}

#ifdef DEBUG
Expand Down Expand Up @@ -1260,8 +1260,7 @@ static int FTPDataGetAlstateProgress(void *tx, uint8_t direction)
FtpDataState *ftpdata_state = (FtpDataState *)tx;
if (direction == ftpdata_state->direction)
return ftpdata_state->state;
else
return FTPDATA_STATE_FINISHED;
return FTPDATA_STATE_FINISHED;
}

static AppLayerGetFileState FTPDataStateGetTxFiles(void *tx, uint8_t direction)
Expand Down

0 comments on commit 75eb6fb

Please sign in to comment.