summaryrefslogtreecommitdiffstats
path: root/adbbu/twrpback.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'adbbu/twrpback.cpp')
-rw-r--r--adbbu/twrpback.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/adbbu/twrpback.cpp b/adbbu/twrpback.cpp
index c59fd1cda..d9b973bcc 100644
--- a/adbbu/twrpback.cpp
+++ b/adbbu/twrpback.cpp
@@ -133,7 +133,12 @@ int twrpback::backup(std::string command) {
}
}
- sprintf(operation, "adbbackup %s", command.c_str());
+ memset(operation, 0, sizeof(operation));
+ if (snprintf(operation, sizeof(operation), "adbbackup %s", command.c_str()) >= sizeof(operation)) {
+ adblogwrite("Operation too big to write to ORS_INPUT_FILE\n");
+ close_backup_fds();
+ return -1;
+ }
if (write(write_fd, operation, sizeof(operation)) != sizeof(operation)) {
adblogwrite("Unable to write to ORS_INPUT_FILE\n");
close_backup_fds();
@@ -173,8 +178,7 @@ int twrpback::backup(std::string command) {
struct AdbBackupControlType structcmd;
memcpy(&structcmd, cmd, sizeof(cmd));
- std::string cmdstr(structcmd.type);
- std::string cmdtype = cmdstr.substr(0, sizeof(structcmd.type) - 1);
+ std::string cmdtype = structcmd.get_type();
//we received an error, exit and unlink
if (cmdtype == TWERROR) {
@@ -396,7 +400,6 @@ int twrpback::backup(std::string command) {
int twrpback::restore(void) {
twrpDigest adb_md5;
- char cmd[MAX_ADB_READ];
char result[MAX_ADB_READ];
struct AdbBackupControlType structcmd;
int adb_control_twrp_fd, errctr = 0;
@@ -436,6 +439,7 @@ int twrpback::restore(void) {
}
}
+ memset(operation, 0, sizeof(operation));
sprintf(operation, "adbrestore");
if (write(write_fd, operation, sizeof(operation)) != sizeof(operation)) {
adblogwrite("Unable to write to ORS_INPUT_FILE\n");
@@ -489,8 +493,7 @@ int twrpback::restore(void) {
if (read(adb_control_bu_fd, &cmd, sizeof(cmd)) > 0) {
struct AdbBackupControlType structcmd;
memcpy(&structcmd, cmd, sizeof(cmd));
- std::string cmdstr(structcmd.type);
- std::string cmdtype = cmdstr.substr(0, sizeof(structcmd.type) - 1);
+ std::string cmdtype = structcmd.get_type();
//If we receive TWEOF from TWRP close adb data fifo
if (cmdtype == TWEOF) {
@@ -516,13 +519,11 @@ int twrpback::restore(void) {
}
//If we should read from the adb stream, write commands and data to TWRP
if (read_from_adb) {
- std::string cmdstr;
int readbytes;
if ((readbytes = fread(result, 1, sizeof(result), adbd_fp)) == sizeof(result)) {
totalbytes += readbytes;
memcpy(&structcmd, result, sizeof(result));
- cmdstr = structcmd.type;
- std::string cmdtype = cmdstr.substr(0, sizeof(structcmd.type) - 1);
+ std::string cmdtype = structcmd.get_type();
//Tell TWRP we have read the entire adb stream
if (cmdtype == TWENDADB) {
@@ -663,9 +664,9 @@ int twrpback::restore(void) {
}
totalbytes += readbytes;
memcpy(&structcmd, result, sizeof(result));
- cmdstr = structcmd.type;
+ std::string cmdtype = structcmd.get_type();
- if (cmdstr.substr(0, sizeof(MD5TRAILER) - 1) == MD5TRAILER) {
+ if (cmdtype.substr(0, sizeof(MD5TRAILER) - 1) == MD5TRAILER) {
struct AdbBackupFileTrailer md5tr;
uint32_t crc, md5trcrc, md5ident, md5identmatch;
@@ -778,6 +779,12 @@ int main(int argc, char **argv) {
return -1;
}
+ if (argc <= 1) {
+ tw.adblogwrite("No parameters given, exiting...\n");
+ tw.close_restore_fds();
+ return -1;
+ }
+
command = argv[1];
for (index = 2; index < argc; index++) {
command = command + " " + argv[index];