system/corennnnn
修订版 | 870f3dff71c50370b3900e00c907812ec3f6c6c7 (tree) |
---|---|
时间 | 2010-04-14 19:12:28 |
作者 | Alexey Tarasov <tarasov@dodo...> |
Commiter | Chih-Wei Huang |
Make get_my_path() safer
Adds maxLen parameter to get_my_path().
Some small cosmetic fixes.
@@ -783,7 +783,7 @@ int launch_server() | ||
783 | 783 | fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno); |
784 | 784 | return -1; |
785 | 785 | } |
786 | - get_my_path(path); | |
786 | + get_my_path(path, PATH_MAX); | |
787 | 787 | pid_t pid = fork(); |
788 | 788 | if(pid < 0) return -1; |
789 | 789 |
@@ -236,7 +236,7 @@ void fatal_errno(const char *fmt, ...); | ||
236 | 236 | void handle_packet(apacket *p, atransport *t); |
237 | 237 | void send_packet(apacket *p, atransport *t); |
238 | 238 | |
239 | -void get_my_path(char s[PATH_MAX]); | |
239 | +void get_my_path(char *s, size_t maxLen); | |
240 | 240 | int launch_server(); |
241 | 241 | int adb_main(int is_daemon); |
242 | 242 |
@@ -50,7 +50,7 @@ enum { | ||
50 | 50 | |
51 | 51 | static int do_cmd(transport_type ttype, char* serial, char *cmd, ...); |
52 | 52 | |
53 | -void get_my_path(char s[PATH_MAX]); | |
53 | +void get_my_path(char *s, size_t maxLen); | |
54 | 54 | int find_sync_dirs(const char *srcarg, |
55 | 55 | char **android_srcdir_out, char **data_srcdir_out); |
56 | 56 | 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]) | ||
673 | 673 | /* If the CWD isn't under a good-looking top, see if the |
674 | 674 | * executable is. |
675 | 675 | */ |
676 | - get_my_path(dir); | |
676 | + get_my_path(dir, PATH_MAX); | |
677 | 677 | top = find_top_from(dir, path_buf); |
678 | 678 | } |
679 | 679 | return top; |
@@ -17,7 +17,7 @@ | ||
17 | 17 | #import <Carbon/Carbon.h> |
18 | 18 | #include <unistd.h> |
19 | 19 | |
20 | -void get_my_path(char s[PATH_MAX]) | |
20 | +void get_my_path(char *s, size_t maxLen) | |
21 | 21 | { |
22 | 22 | ProcessSerialNumber psn; |
23 | 23 | GetCurrentProcess(&psn); |
@@ -25,6 +25,6 @@ void get_my_path(char s[PATH_MAX]) | ||
25 | 25 | dict = ProcessInformationCopyDictionary(&psn, 0xffffffff); |
26 | 26 | CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict, |
27 | 27 | CFSTR("CFBundleExecutable")); |
28 | - CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8); | |
28 | + CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8); | |
29 | 29 | } |
30 | 30 |
@@ -19,15 +19,15 @@ | ||
19 | 19 | #include <limits.h> |
20 | 20 | #include <stdio.h> |
21 | 21 | |
22 | -void get_my_path(char exe[PATH_MAX]) | |
22 | +void get_my_path(char *exe, size_t maxLen) | |
23 | 23 | { |
24 | 24 | char proc[64]; |
25 | 25 | snprintf(proc, sizeof proc, "/proc/%d/exe", getpid()); |
26 | - int err = readlink(proc, exe, PATH_MAX - 1); | |
26 | + int err = readlink(proc, exe, maxLen - 1); | |
27 | 27 | if(err > 0) { |
28 | - exe[err] = 0; | |
28 | + exe[err] = '\0'; | |
29 | 29 | } else { |
30 | - exe[0] = 0; | |
30 | + exe[0] = '\0'; | |
31 | 31 | } |
32 | 32 | } |
33 | 33 |
@@ -18,14 +18,17 @@ | ||
18 | 18 | #include <assert.h> |
19 | 19 | #include <windows.h> |
20 | 20 | |
21 | -void get_my_path(char exe[PATH_MAX]) | |
21 | +void get_my_path(char *exe, size_t maxLen) | |
22 | 22 | { |
23 | - char* r; | |
23 | + char *r; | |
24 | 24 | |
25 | - GetModuleFileName( NULL, exe, PATH_MAX-1 ); | |
26 | - exe[PATH_MAX-1] = 0; | |
27 | - r = strrchr( exe, '\\' ); | |
28 | - if (r) | |
29 | - *r = 0; | |
25 | + /* XXX: should be GetModuleFileNameA */ | |
26 | + if (GetModuleFileName(NULL, exe, maxLen) > 0) { | |
27 | + r = strrchr(exe, '\\'); | |
28 | + if (r != NULL) | |
29 | + *r = '\0'; | |
30 | + } else { | |
31 | + exe[0] = '\0'; | |
32 | + } | |
30 | 33 | } |
31 | 34 |