Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make get_my_path() safer

Adds maxLen parameter to get_my_path().
Some small cosmetic fixes.
  • Loading branch information...
commit 3166410a82f43d39201be98a8d35c51baa86cb53 1 parent 74d7ff8
@taleks taleks authored
View
2  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;
View
2  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);
View
4 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;
View
4 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);
}
View
8 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';
}
}
View
17 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';
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.