summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2014-01-17 16:16:42 -0800
committerNick Kralevich <nnk@google.com>2014-01-17 16:16:42 -0800
commit72917837e6a1163bd389cf535eb404501a118cf2 (patch)
tree21966583e60ff8e6a3bc75b43bbf036705d7e8c4
parent6192eedb43bfa949569850b5cf4a6550b2c62f08 (diff)
downloadsystem_core-72917837e6a1163bd389cf535eb404501a118cf2.zip
system_core-72917837e6a1163bd389cf535eb404501a118cf2.tar.gz
system_core-72917837e6a1163bd389cf535eb404501a118cf2.tar.bz2
Fix "adb push /sdcard/filename"
Don't assume that calling chown(filename, getuid(), getgid()) will always succeed. In the case of /sdcard, a file you create will be owned by root, so the chown call will fail. Instead, use uid=gid=-1 so that the chown call is truly a no-op. Ignore the results of calling chmod. Again, for /sdcard, the chmod call will never succeed, because the file isn't owned by the shell user. Bug: 12441485 Change-Id: I11eaf1d6f6049c1158afc29754fbb7af2baf2c78
-rw-r--r--adb/file_sync_service.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/adb/file_sync_service.c b/adb/file_sync_service.c
index c30f9fb..577fb8f 100644
--- a/adb/file_sync_service.c
+++ b/adb/file_sync_service.c
@@ -43,11 +43,10 @@ static int mkdirs(char *name)
{
int ret;
char *x = name + 1;
- unsigned int uid, gid;
+ uid_t uid = -1;
+ gid_t gid = -1;
unsigned int mode = 0775;
uint64_t cap = 0;
- uid = getuid();
- gid = getgid();
if(name[0] != '/') return -1;
@@ -172,8 +171,8 @@ static int fail_errno(int s)
return fail_message(s, strerror(errno));
}
-static int handle_send_file(int s, char *path, unsigned int uid,
- unsigned int gid, mode_t mode, char *buffer)
+static int handle_send_file(int s, char *path, uid_t uid,
+ gid_t gid, mode_t mode, char *buffer)
{
syncmsg msg;
unsigned int timestamp = 0;
@@ -201,11 +200,13 @@ static int handle_send_file(int s, char *path, unsigned int uid,
fail_errno(s);
errno = 0;
}
- /* fchown clears the setuid bit - restore it if present */
- if(fchmod(fd, mode) != 0) {
- fail_errno(s);
- errno = 0;
- }
+
+ /*
+ * fchown clears the setuid bit - restore it if present.
+ * Ignore the result of calling fchmod. It's not supported
+ * by all filesystems. b/12441485
+ */
+ fchmod(fd, mode);
}
for(;;) {
@@ -350,10 +351,9 @@ static int do_send(int s, char *path, char *buffer)
#else
{
#endif
- unsigned int uid, gid;
+ uid_t uid = -1;
+ gid_t gid = -1;
uint64_t cap = 0;
- uid = getuid();
- gid = getgid();
/* copy user permission bits to "group" and "other" permissions */
mode |= ((mode >> 3) & 0070);