Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bfabab0 authored by Ethan Yonker's avatar Ethan Yonker Committed by Dees Troy
Browse files

Check for valid MTP_Storage_ID before adding or removing

Attempting to add a storage ID of 0 was causing a seg fault.

Change-Id: If8797186405be36ee70dbca63bd1063a62ba2812
parent f9f99bcb
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -170,11 +170,15 @@ int twmtp_MtpServer::mtppipe_thread(void)
		if (read_count == sizeof(mtp_message)) {
			if (mtp_message.message_type == MTP_MESSAGE_ADD_STORAGE) {
				MTPI("mtppipe add storage %i '%s'\n", mtp_message.storage_id, mtp_message.path);
				if (mtp_message.storage_id) {
					long reserveSpace = 1;
					bool removable = false;
					MtpStorage* storage = new MtpStorage(mtp_message.storage_id, mtp_message.path, mtp_message.display, reserveSpace, removable, mtp_message.maxFileSize, refserver);
					server->addStorage(storage);
					MTPD("mtppipe done adding storage\n");
				} else {
					MTPE("Invalid storage ID %i specified\n", mtp_message.storage_id);
				}
			} else if (mtp_message.message_type == MTP_MESSAGE_REMOVE_STORAGE) {
				MTPI("mtppipe remove storage %i\n", mtp_message.storage_id);
				remove_storage(mtp_message.storage_id);
+2 −0
Original line number Diff line number Diff line
@@ -2015,6 +2015,8 @@ bool TWPartitionManager::Add_Remove_MTP_Storage(TWPartition* Part, int message_t
	}

	if (Part) {
		if (Part->MTP_Storage_ID == 0)
			return false;
		if (message_type == MTP_MESSAGE_REMOVE_STORAGE) {
			mtp_message.message_type = MTP_MESSAGE_REMOVE_STORAGE; // Remove
			LOGINFO("sending message to remove %i\n", Part->MTP_Storage_ID);