summaryrefslogtreecommitdiffstats
path: root/adb
diff options
context:
space:
mode:
authorAlexey Tarasov <tarasov@dodologics.com>2009-10-22 02:55:00 +1100
committerAlexey Tarasov <tarasov@dodologics.com>2009-10-22 02:55:00 +1100
commit3166410a82f43d39201be98a8d35c51baa86cb53 (patch)
tree484564e35ef296e3e2a029d5710bee7c672f1129 /adb
parent74d7ff8cfd490852d3df1c4b9d8a21beed619caa (diff)
downloadsystem_core-3166410a82f43d39201be98a8d35c51baa86cb53.zip
system_core-3166410a82f43d39201be98a8d35c51baa86cb53.tar.gz
system_core-3166410a82f43d39201be98a8d35c51baa86cb53.tar.bz2
Make get_my_path() safer
Adds maxLen parameter to get_my_path(). Some small cosmetic fixes.
Diffstat (limited to 'adb')
-rw-r--r--adb/adb.c2
-rw-r--r--adb/adb.h2
-rw-r--r--adb/commandline.c4
-rw-r--r--adb/get_my_path_darwin.c4
-rw-r--r--adb/get_my_path_linux.c8
-rw-r--r--adb/get_my_path_windows.c17
6 files changed, 20 insertions, 17 deletions
diff --git a/adb/adb.c b/adb/adb.c
index c1646b8..7df3f7b 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -783,7 +783,7 @@ int launch_server()
fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
return -1;
}
- get_my_path(path);
+ get_my_path(path, PATH_MAX);
pid_t pid = fork();
if(pid < 0) return -1;
diff --git a/adb/adb.h b/adb/adb.h
index b958682..a148019 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -236,7 +236,7 @@ void fatal_errno(const char *fmt, ...);
void handle_packet(apacket *p, atransport *t);
void send_packet(apacket *p, atransport *t);
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
int launch_server();
int adb_main(int is_daemon);
diff --git a/adb/commandline.c b/adb/commandline.c
index 055aa10..52bcedc 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -50,7 +50,7 @@ enum {
static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
-void get_my_path(char s[PATH_MAX]);
+void get_my_path(char *s, size_t maxLen);
int find_sync_dirs(const char *srcarg,
char **android_srcdir_out, char **data_srcdir_out);
int install_app(transport_type transport, char* serial, int argc, char** argv);
@@ -673,7 +673,7 @@ static char *find_top(char path_buf[PATH_MAX])
/* If the CWD isn't under a good-looking top, see if the
* executable is.
*/
- get_my_path(dir);
+ get_my_path(dir, PATH_MAX);
top = find_top_from(dir, path_buf);
}
return top;
diff --git a/adb/get_my_path_darwin.c b/adb/get_my_path_darwin.c
index 6125cb4..5b95d15 100644
--- a/adb/get_my_path_darwin.c
+++ b/adb/get_my_path_darwin.c
@@ -17,7 +17,7 @@
#import <Carbon/Carbon.h>
#include <unistd.h>
-void get_my_path(char s[PATH_MAX])
+void get_my_path(char *s, size_t maxLen)
{
ProcessSerialNumber psn;
GetCurrentProcess(&psn);
@@ -25,6 +25,6 @@ void get_my_path(char s[PATH_MAX])
dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict,
CFSTR("CFBundleExecutable"));
- CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8);
+ CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8);
}
diff --git a/adb/get_my_path_linux.c b/adb/get_my_path_linux.c
index f516e59..179c3dd 100644
--- a/adb/get_my_path_linux.c
+++ b/adb/get_my_path_linux.c
@@ -19,15 +19,15 @@
#include <limits.h>
#include <stdio.h>
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
{
char proc[64];
snprintf(proc, sizeof proc, "/proc/%d/exe", getpid());
- int err = readlink(proc, exe, PATH_MAX - 1);
+ int err = readlink(proc, exe, maxLen - 1);
if(err > 0) {
- exe[err] = 0;
+ exe[err] = '\0';
} else {
- exe[0] = 0;
+ exe[0] = '\0';
}
}
diff --git a/adb/get_my_path_windows.c b/adb/get_my_path_windows.c
index fc7143c..ddf2816 100644
--- a/adb/get_my_path_windows.c
+++ b/adb/get_my_path_windows.c
@@ -18,14 +18,17 @@
#include <assert.h>
#include <windows.h>
-void get_my_path(char exe[PATH_MAX])
+void get_my_path(char *exe, size_t maxLen)
{
- char* r;
+ char *r;
- GetModuleFileName( NULL, exe, PATH_MAX-1 );
- exe[PATH_MAX-1] = 0;
- r = strrchr( exe, '\\' );
- if (r)
- *r = 0;
+ /* XXX: should be GetModuleFileNameA */
+ if (GetModuleFileName(NULL, exe, maxLen) > 0) {
+ r = strrchr(exe, '\\');
+ if (r != NULL)
+ *r = '\0';
+ } else {
+ exe[0] = '\0';
+ }
}