Skip to content
This repository has been archived by the owner on Apr 25, 2022. It is now read-only.

Commit

Permalink
dfuzzer: drop the package-info parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
mrc0mmand committed Feb 24, 2022
1 parent c749c69 commit 58ae664
Showing 1 changed file with 3 additions and 73 deletions.
76 changes: 3 additions & 73 deletions src/dfuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,10 @@ int df_get_pid(const GDBusConnection *dcon)
*/
void df_print_process_info(int pid)
{
char proc_path[15+DECIMAL_STR_MAX(int)]; // "/proc/(int)/[exe|cmdline]"
char name[PATH_MAX + 1]; // for storing process and package name
char buf[PATH_MAX + MAXLEN]; // buffer for rpm/dpkg request
FILE *fp;
char proc_path[15 + DECIMAL_STR_MAX(int)]; // "/proc/(int)/[exe|cmdline]"
char name[PATH_MAX + 1];
_cleanup_close_ int fd = -1;
int stdoutcpy, stderrcpy, ret;
int ret;

sprintf(proc_path, "/proc/%d/exe", pid);
ret = readlink(proc_path, name, PATH_MAX);
Expand Down Expand Up @@ -974,74 +972,6 @@ void df_print_process_info(int pid)

fprintf(stderr, "%s%s[PROCESS: %s%s\n",
ansi_cr(), ansi_cyan(), name, ansi_normal());

// excludes interprets
if (strstr(name, "python") || strstr(name, "perl")) {
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
return;
}


fd = open("/dev/null", O_RDWR, S_IRUSR | S_IWUSR);
if (fd == -1) {
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
return;
}

// backup std descriptors
stdoutcpy = dup(1);
stderrcpy = dup(2);

// make stdout and stderr go to fd
if (dup2(fd, 1) == -1) {
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
return;
}
if (dup2(fd, 2) == -1) {
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
dup2(stdoutcpy, 1);
close(stdoutcpy);
return;
}
close(fd); // fd no longer needed


// Determines which package manager should be used
if (WEXITSTATUS(system("which rpm")) == 0)
sprintf(buf, "rpm -qf %s", name);
else if (WEXITSTATUS(system("which dpkg")) == 0)
sprintf(buf, "aptitude versions $(dpkg -S %s "
"| sed 's/:.*//') -F %%p %%V | sed 's/Package //' "
"| sed ':a;$!N;s/:\\n/-/;ta' | tr -d ' ' | sed '/^$/d' "
"| tr '\n' ' ' | sed 's/$/\\n$/'" , name);
else { // only rpm/dpkg are supported
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
// restore std descriptors
dup2(stdoutcpy, 1);
close(stdoutcpy);
dup2(stderrcpy, 2);
close(stderrcpy);
return;
}

fp = popen(buf, "r");
// restore std descriptors
dup2(stdoutcpy, 1);
close(stdoutcpy);
dup2(stderrcpy, 2);
close(stderrcpy);
if (fp == NULL) {
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
return;
}
fgets(name, PATH_MAX, fp);
ret = pclose(fp);


if (WEXITSTATUS(ret) == 0)
fprintf(stderr, "%s%s[PACKAGE: %s%s\n", ansi_cr(), ansi_cyan(), name, ansi_normal());
else
fprintf(stderr, "%s%s[PACKAGE: %s\n", ansi_cr(), ansi_cyan(), ansi_normal());
}

/**
Expand Down

0 comments on commit 58ae664

Please sign in to comment.