Refuse to push a non-regular file server
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 <https://github.com/Genymobile/scrcpy/issues/956>
This commit is contained in:
parent
3259c60b22
commit
64bcac9157
3 changed files with 24 additions and 1 deletions
|
@ -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"
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue