Skip to content

Commit 88fef1c

Browse files
authored
PVS-Studio pipeline (#18)
1 parent 4f2c94d commit 88fef1c

File tree

12 files changed

+112
-63
lines changed

12 files changed

+112
-63
lines changed

.github/workflows/pvsstudio.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: PVS-Studio build analysis
2+
on: workflow_dispatch
3+
jobs:
4+
build-analyze:
5+
runs-on: ubuntu-latest
6+
env:
7+
FBT_NO_SYNC: "true"
8+
TARGETS: f7
9+
DEFAULT_TARGET: f7
10+
steps:
11+
- name: 'Decontaminate previous build leftovers'
12+
run: |
13+
if [ -d .git ]; then
14+
git submodule status || git checkout "$(git rev-list --max-parents=0 HEAD | tail -n 1)"
15+
fi
16+
- uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
19+
submodules: 'recursive'
20+
- name: Install tools
21+
run: |
22+
wget -q -O - https://files.pvs-studio.com/etc/pubkey.txt \
23+
| sudo apt-key add -
24+
sudo wget -O /etc/apt/sources.list.d/viva64.list \
25+
https://files.pvs-studio.com/etc/viva64.list
26+
sudo apt update
27+
sudo apt install pvs-studio
28+
pvs-studio-analyzer credentials ${{ secrets.PVS_STUDIO_CREDENTIALS }}
29+
- name: Build
30+
run: |
31+
./pvs-build
32+
- name: Analyze
33+
run: |
34+
pvs-studio-analyzer analyze @.pvsoptions -j$(grep -c processor /proc/cpuinfo) -f flipperzero-firmware_unleashed/build/f7-firmware-DC/compile_commands.json
35+
- name: Convert report
36+
run: |
37+
plog-converter -t sarif -o pvs-report.sarif PVS-Studio.log
38+
- name: Publish report
39+
uses: github/codeql-action/upload-sarif@v1
40+
with:
41+
sarif_file: pvs-report.sarif
42+
category: PVS-Studio

.pvsconfig

Whitespace-only changes.

.pvsoptions

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--rules-config .pvsconfig -e flipperzero-firmware_unleashed -e flipperzero-firmware_official

build.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ function Get-LatestDirectory {
66
Get-ChildItem -Path $Path | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
77
}
88

9-
./fbt u fap_totp
10-
./fbt o fap_totp
9+
./fbt u COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
10+
./fbt o COMPACT=1 DEBUG=0 VERBOSE=0 fap_totp
1111

1212
Push-Location $PSScriptRoot
1313

pvs-build

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
pushd flipperzero-firmware_unleashed
4+
rm -rf applications/plugins/totp
5+
sed -i 's/applications_user/../' site_scons/commandline.scons
6+
./fbt COMPACT=1 firmware_cdb fap_totp
7+
popd

totp/scenes/add_new_token/totp_scene_add_new_token.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState
251251
tokenInfo->algo = scene_state->algo;
252252
tokenInfo->digits = scene_state->digits_count;
253253

254-
if(plugin_state->tokens_list == NULL) {
255-
plugin_state->tokens_list = list_init_head(tokenInfo);
256-
} else {
257-
list_add(plugin_state->tokens_list, tokenInfo);
258-
}
254+
TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, tokenInfo);
259255
plugin_state->tokens_count++;
260256

261257
totp_config_file_save_new_token(tokenInfo);

totp/services/cli/commands/add/add.c

+40-43
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,43 @@ static void furi_string_secure_free(FuriString* str) {
8787
furi_string_free(str);
8888
}
8989

90+
static bool totp_cli_read_secret(Cli* cli, FuriString* out_str, bool mask_user_input) {
91+
uint8_t c;
92+
while(cli_read(cli, &c, 1) == 1) {
93+
if(c == CliSymbolAsciiEsc) {
94+
// Some keys generating escape-sequences
95+
// We need to ignore them as we case about alpha-numerics only
96+
uint8_t c2;
97+
cli_read_timeout(cli, &c2, 1, 0);
98+
cli_read_timeout(cli, &c2, 1, 0);
99+
} else if(c == CliSymbolAsciiETX) {
100+
TOTP_CLI_DELETE_CURRENT_LINE();
101+
TOTP_CLI_PRINTF("Cancelled by user\r\n");
102+
return false;
103+
} else if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
104+
if(mask_user_input) {
105+
putc('*', stdout);
106+
} else {
107+
putc(c, stdout);
108+
}
109+
fflush(stdout);
110+
furi_string_push_back(out_str, c);
111+
} else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
112+
size_t out_str_size = furi_string_size(out_str);
113+
if(out_str_size > 0) {
114+
TOTP_CLI_DELETE_LAST_CHAR();
115+
furi_string_left(out_str, out_str_size - 1);
116+
}
117+
} else if(c == CliSymbolAsciiCR) {
118+
cli_nl();
119+
break;
120+
}
121+
}
122+
123+
TOTP_CLI_DELETE_LAST_LINE();
124+
return true;
125+
}
126+
90127
void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
91128
FuriString* temp_str = furi_string_alloc();
92129
TokenInfo* token_info = token_info_alloc();
@@ -148,44 +185,8 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
148185
// Reading token secret
149186
furi_string_reset(temp_str);
150187
TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n");
151-
152-
uint8_t c;
153-
while(cli_read(cli, &c, 1) == 1) {
154-
if(c == CliSymbolAsciiEsc) {
155-
// Some keys generating escape-sequences
156-
// We need to ignore them as we case about alpha-numerics only
157-
uint8_t c2;
158-
cli_read_timeout(cli, &c2, 1, 0);
159-
cli_read_timeout(cli, &c2, 1, 0);
160-
} else if(c == CliSymbolAsciiETX) {
161-
TOTP_CLI_DELETE_CURRENT_LINE();
162-
TOTP_CLI_PRINTF("Cancelled by user\r\n");
163-
furi_string_secure_free(temp_str);
164-
token_info_free(token_info);
165-
return;
166-
} else if((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
167-
if(mask_user_input) {
168-
putc('*', stdout);
169-
} else {
170-
putc(c, stdout);
171-
}
172-
fflush(stdout);
173-
furi_string_push_back(temp_str, c);
174-
} else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) {
175-
size_t temp_str_size = furi_string_size(temp_str);
176-
if(temp_str_size > 0) {
177-
TOTP_CLI_DELETE_LAST_CHAR();
178-
furi_string_left(temp_str, temp_str_size - 1);
179-
}
180-
} else if(c == CliSymbolAsciiCR) {
181-
cli_nl();
182-
break;
183-
}
184-
}
185-
186-
TOTP_CLI_DELETE_LAST_LINE();
187-
188-
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
188+
if(!totp_cli_read_secret(cli, temp_str, mask_user_input) ||
189+
!totp_cli_ensure_authenticated(plugin_state, cli)) {
189190
furi_string_secure_free(temp_str);
190191
token_info_free(token_info);
191192
return;
@@ -210,11 +211,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
210211
load_generate_token_scene = true;
211212
}
212213

213-
if(plugin_state->tokens_list == NULL) {
214-
plugin_state->tokens_list = list_init_head(token_info);
215-
} else {
216-
list_add(plugin_state->tokens_list, token_info);
217-
}
214+
TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, token_info);
218215
plugin_state->tokens_count++;
219216
totp_config_file_save_new_token(token_info);
220217

totp/services/config/config.c

+1-5
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,7 @@ TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state)
409409

410410
FURI_LOG_D(LOGGING_TAG, "Found token \"%s\"", tokenInfo->name);
411411

412-
if(plugin_state->tokens_list == NULL) {
413-
plugin_state->tokens_list = list_init_head(tokenInfo);
414-
} else {
415-
list_add(plugin_state->tokens_list, tokenInfo);
416-
}
412+
TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, tokenInfo);
417413

418414
index++;
419415
}

totp/services/list/list.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ListNode* list_add(ListNode* head, void* data) {
2626
return head;
2727
}
2828

29-
ListNode* list_find(ListNode* head, void* data) {
29+
ListNode* list_find(ListNode* head, const void* data) {
3030
ListNode* it;
3131

3232
for(it = head; it != NULL; it = it->next)
@@ -66,7 +66,8 @@ ListNode* list_remove(ListNode* head, ListNode* ep) {
6666
}
6767

6868
void list_free(ListNode* head) {
69-
ListNode *it = head, *tmp;
69+
ListNode* it = head;
70+
ListNode* tmp;
7071

7172
while(it != NULL) {
7273
tmp = it;

totp/services/list/list.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ ListNode* list_add(
1414
void* data); /* adds element with specified data to the end of the list and returns new head node. */
1515
ListNode* list_find(
1616
ListNode* head,
17-
void* data); /* returns pointer of element with specified data in list. */
17+
const void* data); /* returns pointer of element with specified data in list. */
1818
ListNode* list_element_at(
1919
ListNode* head,
2020
uint16_t index); /* returns pointer of element with specified index in list. */
2121
ListNode* list_remove(
2222
ListNode* head,
2323
ListNode* ep); /* removes element from the list and returns new head node. */
2424
void list_free(ListNode* head); /* deletes all elements of the list. */
25+
26+
#define TOTP_LIST_INIT_OR_ADD(head, item) \
27+
do { \
28+
if(head == NULL) { \
29+
head = list_init_head(item); \
30+
} else { \
31+
list_add(head, item); \
32+
} \
33+
} while(false)

totp/types/token_info.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ bool token_info_set_secret(
2525
TokenInfo* token_info,
2626
const char* base32_token_secret,
2727
size_t token_secret_length,
28-
uint8_t* iv) {
28+
const uint8_t* iv) {
2929
uint8_t* plain_secret = malloc(token_secret_length);
3030
int plain_secret_length =
31-
base32_decode((uint8_t*)base32_token_secret, plain_secret, token_secret_length);
31+
base32_decode((const uint8_t*)base32_token_secret, plain_secret, token_secret_length);
3232
bool result;
3333
if(plain_secret_length >= 0) {
3434
token_info->token =
@@ -43,7 +43,7 @@ bool token_info_set_secret(
4343
return result;
4444
}
4545

46-
uint8_t token_info_get_digits_count(TokenInfo* token_info) {
46+
uint8_t token_info_get_digits_count(const TokenInfo* token_info) {
4747
switch(token_info->digits) {
4848
case TOTP_6_DIGITS:
4949
return 6;

totp/types/token_info.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ bool token_info_set_secret(
2020
TokenInfo* token_info,
2121
const char* base32_token_secret,
2222
size_t token_secret_length,
23-
uint8_t* iv);
24-
uint8_t token_info_get_digits_count(TokenInfo* token_info);
23+
const uint8_t* iv);
24+
uint8_t token_info_get_digits_count(const TokenInfo* token_info);

0 commit comments

Comments
 (0)