Skip to content

Commit

Permalink
Refuse to push a non-regular file server
Browse files Browse the repository at this point in the history
If SCRCPY_SERVER_PATH points to a directory, then a directory will be
pushed to /data/local/tmp/scrcpy-server.jar.

When executing it, app_process will just abort and leave the directory
on the device, causing scrcpy to always fail.

To avoid the problem, check that the server is a regular file before
pushing it.

Closes #956 <#956>
  • Loading branch information
rom1v committed Dec 5, 2019
1 parent 3259c60 commit 64bcac9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "config.h"
#include "common.h"
Expand Down Expand Up @@ -202,3 +205,14 @@ process_check_success(process_t proc, const char *name) {
}
return true;
}

bool
is_regular_file(const char *path) {
struct stat path_stat;
int r = stat(path, &path_stat);
if (r) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}
4 changes: 4 additions & 0 deletions app/src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ process_check_success(process_t proc, const char *name);
char *
get_executable_path(void);

// returns true if the file exists and is not a directory
bool
is_regular_file(const char *path);

#endif
7 changes: 6 additions & 1 deletion app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ get_server_path(void) {

static bool
push_server(const char *serial) {
process_t process = adb_push(serial, get_server_path(), DEVICE_SERVER_PATH);
const char *server_path = get_server_path();
if (!is_regular_file(server_path)) {
LOGE("'%s' does not exist or is not a regular file\n", server_path);
return false;
}
process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH);
return process_check_success(process, "adb push");
}

Expand Down

0 comments on commit 64bcac9

Please sign in to comment.