• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revision870f3dff71c50370b3900e00c907812ec3f6c6c7 (tree)
Zeit2010-04-14 19:12:28
AutorAlexey Tarasov <tarasov@dodo...>
CommiterChih-Wei Huang

Log Message

Make get_my_path() safer

Adds maxLen parameter to get_my_path().
Some small cosmetic fixes.

Ändern Zusammenfassung

Diff

--- a/adb/adb.c
+++ b/adb/adb.c
@@ -783,7 +783,7 @@ int launch_server()
783783 fprintf(stderr, "pipe failed in launch_server, errno: %d\n", errno);
784784 return -1;
785785 }
786- get_my_path(path);
786+ get_my_path(path, PATH_MAX);
787787 pid_t pid = fork();
788788 if(pid < 0) return -1;
789789
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -236,7 +236,7 @@ void fatal_errno(const char *fmt, ...);
236236 void handle_packet(apacket *p, atransport *t);
237237 void send_packet(apacket *p, atransport *t);
238238
239-void get_my_path(char s[PATH_MAX]);
239+void get_my_path(char *s, size_t maxLen);
240240 int launch_server();
241241 int adb_main(int is_daemon);
242242
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -50,7 +50,7 @@ enum {
5050
5151 static int do_cmd(transport_type ttype, char* serial, char *cmd, ...);
5252
53-void get_my_path(char s[PATH_MAX]);
53+void get_my_path(char *s, size_t maxLen);
5454 int find_sync_dirs(const char *srcarg,
5555 char **android_srcdir_out, char **data_srcdir_out);
5656 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])
673673 /* If the CWD isn't under a good-looking top, see if the
674674 * executable is.
675675 */
676- get_my_path(dir);
676+ get_my_path(dir, PATH_MAX);
677677 top = find_top_from(dir, path_buf);
678678 }
679679 return top;
--- a/adb/get_my_path_darwin.c
+++ b/adb/get_my_path_darwin.c
@@ -17,7 +17,7 @@
1717 #import <Carbon/Carbon.h>
1818 #include <unistd.h>
1919
20-void get_my_path(char s[PATH_MAX])
20+void get_my_path(char *s, size_t maxLen)
2121 {
2222 ProcessSerialNumber psn;
2323 GetCurrentProcess(&psn);
@@ -25,6 +25,6 @@ void get_my_path(char s[PATH_MAX])
2525 dict = ProcessInformationCopyDictionary(&psn, 0xffffffff);
2626 CFStringRef value = (CFStringRef)CFDictionaryGetValue(dict,
2727 CFSTR("CFBundleExecutable"));
28- CFStringGetCString(value, s, PATH_MAX - 1, kCFStringEncodingUTF8);
28+ CFStringGetCString(value, s, maxLen, kCFStringEncodingUTF8);
2929 }
3030
--- a/adb/get_my_path_linux.c
+++ b/adb/get_my_path_linux.c
@@ -19,15 +19,15 @@
1919 #include <limits.h>
2020 #include <stdio.h>
2121
22-void get_my_path(char exe[PATH_MAX])
22+void get_my_path(char *exe, size_t maxLen)
2323 {
2424 char proc[64];
2525 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);
2727 if(err > 0) {
28- exe[err] = 0;
28+ exe[err] = '\0';
2929 } else {
30- exe[0] = 0;
30+ exe[0] = '\0';
3131 }
3232 }
3333
--- a/adb/get_my_path_windows.c
+++ b/adb/get_my_path_windows.c
@@ -18,14 +18,17 @@
1818 #include <assert.h>
1919 #include <windows.h>
2020
21-void get_my_path(char exe[PATH_MAX])
21+void get_my_path(char *exe, size_t maxLen)
2222 {
23- char* r;
23+ char *r;
2424
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+ }
3033 }
3134