rpc: additional verification of message data (#1576)

* rpc: additional verification of message data
* rpc: storage: fixed read handler
* acessor: fixed record naming
This commit is contained in:
hedger 2022-08-11 11:28:57 +03:00 committed by GitHub
parent 1d50a5981e
commit add2497a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 19 deletions

View File

@ -32,14 +32,14 @@ void AccessorApp::run(void) {
} }
AccessorApp::AccessorApp() { AccessorApp::AccessorApp() {
notification = static_cast<NotificationApp*>(furi_record_open("notification")); notification = static_cast<NotificationApp*>(furi_record_open(RECORD_NOTIFICATION));
onewire_host = onewire_host_alloc(); onewire_host = onewire_host_alloc();
furi_hal_power_enable_otg(); furi_hal_power_enable_otg();
} }
AccessorApp::~AccessorApp() { AccessorApp::~AccessorApp() {
furi_hal_power_disable_otg(); furi_hal_power_disable_otg();
furi_record_close("notification"); furi_record_close(RECORD_NOTIFICATION);
onewire_host_free(onewire_host); onewire_host_free(onewire_host);
} }

View File

@ -15,7 +15,7 @@ AccessorAppViewManager::AccessorAppViewManager() {
popup = popup_alloc(); popup = popup_alloc();
add_view(ViewType::Popup, popup_get_view(popup)); add_view(ViewType::Popup, popup_get_view(popup));
gui = static_cast<Gui*>(furi_record_open("gui")); gui = static_cast<Gui*>(furi_record_open(RECORD_GUI));
view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen); view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen);
// set previous view callback for all views // set previous view callback for all views
@ -31,6 +31,7 @@ AccessorAppViewManager::~AccessorAppViewManager() {
view_dispatcher, static_cast<uint32_t>(AccessorAppViewManager::ViewType::Popup)); view_dispatcher, static_cast<uint32_t>(AccessorAppViewManager::ViewType::Popup));
// free view modules // free view modules
furi_record_close(RECORD_GUI);
submenu_free(submenu); submenu_free(submenu);
popup_free(popup); popup_free(popup);

View File

@ -297,9 +297,9 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
const char* path = request->content.storage_read_request.path; const char* path = request->content.storage_read_request.path;
Storage* fs_api = furi_record_open(RECORD_STORAGE); Storage* fs_api = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(fs_api); File* file = storage_file_alloc(fs_api);
bool result = false; bool fs_operation_success = storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING);
if(storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) { if(fs_operation_success) {
size_t size_left = storage_file_size(file); size_t size_left = storage_file_size(file);
do { do {
response->command_id = request->command_id; response->command_id = request->command_id;
@ -310,28 +310,25 @@ static void rpc_system_storage_read_process(const PB_Main* request, void* contex
if(read_size) { if(read_size) {
response->content.storage_read_response.has_file = true; response->content.storage_read_response.has_file = true;
response->content.storage_read_response.file.data = response->content.storage_read_response.file.data =
malloc(PB_BYTES_ARRAY_T_ALLOCSIZE()); malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(read_size));
uint8_t* buffer = response->content.storage_read_response.file.data->bytes; uint8_t* buffer = &response->content.storage_read_response.file.data->bytes[0];
uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size; uint16_t* read_size_msg = &response->content.storage_read_response.file.data->size;
*read_size_msg = storage_file_read(file, buffer, read_size); *read_size_msg = storage_file_read(file, buffer, read_size);
size_left -= read_size; size_left -= *read_size_msg;
result = (*read_size_msg == read_size); fs_operation_success = (*read_size_msg == read_size);
response->has_next = result && (size_left > 0); response->has_next = fs_operation_success && (size_left > 0);
} else { } else {
response->content.storage_read_response.has_file = false; response->content.storage_read_response.has_file = false;
response->has_next = false; response->has_next = false;
result = true; fs_operation_success = true;
} }
} while((size_left != 0) && fs_operation_success);
}
rpc_send_and_release(session, response); if(fs_operation_success) {
} while((size_left != 0) && result); rpc_send_and_release(session, response);
if(!result) {
rpc_send_and_release_empty(
session, request->command_id, rpc_system_storage_get_file_error(file));
}
} else { } else {
rpc_send_and_release_empty( rpc_send_and_release_empty(
session, request->command_id, rpc_system_storage_get_file_error(file)); session, request->command_id, rpc_system_storage_get_file_error(file));
@ -384,7 +381,9 @@ static void rpc_system_storage_write_process(const PB_Main* request, void* conte
bool send_response = false; bool send_response = false;
if(fs_operation_success) { if(fs_operation_success) {
if(request->content.storage_write_request.has_file) { if(request->content.storage_write_request.has_file &&
request->content.storage_write_request.file.data &&
request->content.storage_write_request.file.data->size) {
uint8_t* buffer = request->content.storage_write_request.file.data->bytes; uint8_t* buffer = request->content.storage_write_request.file.data->bytes;
size_t buffer_size = request->content.storage_write_request.file.data->size; size_t buffer_size = request->content.storage_write_request.file.data->size;
uint16_t written_size = storage_file_write(file, buffer, buffer_size); uint16_t written_size = storage_file_write(file, buffer, buffer_size);