Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 24, 2023
1 parent baf28bd commit 1aa9e88
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions src/linux/system-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static gchar mntent_buf [PATH_MAX * 4] = {0};
static void frida_collect_process_info (guint pid, FridaEnumerateProcessesOperation * op);
static gboolean frida_is_mount_noexec (struct mntent * mntent);
static gboolean frida_is_directory_noexec (const gchar * directory);
static gchar * get_application_directory (void);
static gchar * frida_get_application_directory (void);
static gboolean frida_add_process_metadata (GHashTable * parameters, const gchar * proc_entry_name);
static GDateTime * frida_query_boot_time (void);
static GVariant * frida_uid_to_name (uid_t uid);
Expand Down Expand Up @@ -185,21 +185,17 @@ frida_temporary_directory_get_system_tmp (void)
* to validate an ordered list of potential locations.
*/
if (frida_is_directory_noexec (tmp_dir))
{
return get_application_directory ();
}
return frida_get_application_directory ();
else
{
return g_strdup (tmp_dir);
}
}

static gboolean
frida_is_directory_noexec (const gchar * directory)
{
struct stat directory_stat, current_stat;
FILE *fp = NULL;
struct mntent mntent, *current;
FILE * fp = NULL;
struct mntent mntent, * current;

/*
* Since the mounting of the temporary filesystem as `noexec` is not that
Expand All @@ -214,37 +210,37 @@ frida_is_directory_noexec (const gchar * directory)
* busybox. It finds the mounted filesystem on which a given directory resides
* and checks the mount options for `noexec`.
*/
if (stat(directory, &directory_stat) != 0)
if (stat (directory, &directory_stat) != 0)
goto beach;

if (!S_ISDIR(directory_stat.st_mode))
if (!S_ISDIR (directory_stat.st_mode))
goto beach;

fp = setmntent ("/proc/mounts", "r");
if (fp == NULL)
goto beach;

for (
current = getmntent_r(fp, &mntent, mntent_buf, sizeof (mntent_buf));
current = getmntent_r (fp, &mntent, mntent_buf, sizeof (mntent_buf));
current != NULL;
current = getmntent_r(fp, &mntent, mntent_buf, sizeof (mntent_buf)))
current = getmntent_r (fp, &mntent, mntent_buf, sizeof (mntent_buf)))
{
/*
* In Linux 2.6 rootfs mount always exists, and it makes sense to always
* ignore it.
*/
if (g_strcmp0(current->mnt_fsname, "rootfs") == 0)
if (g_strcmp0 (current->mnt_fsname, "rootfs") == 0)
continue;

/* If the directory name matches the mountpoint */
if (g_strcmp0(directory, current->mnt_dir) == 0)
if (g_strcmp0 (directory, current->mnt_dir) == 0)
{
noexec = frida_is_mount_noexec (current);
break;
}

/* If the directory name matches mounted the device name */
if (g_strcmp0(directory, current->mnt_fsname) == 0)
if (g_strcmp0 (directory, current->mnt_fsname) == 0)
{
noexec = frida_is_mount_noexec (current);
break;
Expand All @@ -254,7 +250,7 @@ frida_is_directory_noexec (const gchar * directory)
if (current->mnt_fsname[0] == '/')
{
/* Match the directory and device dev_t */
if (stat(current->mnt_fsname, &current_stat) == 0)
if (stat (current->mnt_fsname, &current_stat) == 0)
{
if (current_stat.st_rdev == directory_stat.st_dev)
{
Expand All @@ -265,7 +261,7 @@ frida_is_directory_noexec (const gchar * directory)
}

/* Match the directory and mount point's dev_t */
if (stat(current->mnt_dir, &current_stat) == 0)
if (stat (current->mnt_dir, &current_stat) == 0)
{
if (current_stat.st_dev == directory_stat.st_dev)
{
Expand All @@ -292,10 +288,10 @@ frida_is_mount_noexec (struct mntent * mntent)
}

static gchar *
get_application_directory (void)
frida_get_application_directory (void)
{
gchar* exe_path = NULL;
gchar* exe_dir = NULL;
gchar * exe_path = NULL;
gchar * exe_dir = NULL;

exe_path = g_file_read_link ("/proc/self/exe", NULL);
if (exe_path == NULL)
Expand All @@ -304,8 +300,7 @@ get_application_directory (void)
exe_dir = g_path_get_dirname (exe_path);

beach:
if (exe_path != NULL)
g_free (exe_path);
g_free (exe_path);

return exe_dir;
}
Expand Down

0 comments on commit 1aa9e88

Please sign in to comment.