Added a cleaner way of allocating the zenity command.
This commit is contained in:
parent
3157940c0b
commit
c4ef955ff1
@ -64,15 +64,24 @@ void destroy_ui_socket(void) {
|
||||
*/
|
||||
access_t ask_access(const char *filename, struct process_info proc_info) {
|
||||
FILE *fp = NULL;
|
||||
size_t command_len =
|
||||
139 + sizeof(pid_t) * 8 + strlen(proc_info.name) + strlen(filename);
|
||||
char *command = (char *)malloc(command_len);
|
||||
snprintf(command, command_len,
|
||||
char *command = NULL;
|
||||
int ret =
|
||||
asprintf(&command,
|
||||
"zenity --question --extra-button \"Allow this time\" --title "
|
||||
"\"Allow Access?\" --text \"Allow process "
|
||||
"<tt>%s</tt> with PID <tt>%d</tt> to access <tt>%s</tt>\"",
|
||||
proc_info.name, proc_info.PID, filename);
|
||||
|
||||
if (ret < 0) {
|
||||
// If asprintf fails, the contents of command are undefined (see man
|
||||
// asprintf). That does not explicitly rule out that command will be a valid
|
||||
// pointer. But the risk of freeing a non-allocated pointer is too much to
|
||||
// justify preparing for this.
|
||||
fprintf(stderr, "Could not create query on rule insertion");
|
||||
perror("");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Zenity Question Message Popup
|
||||
fp = popen(command, "r");
|
||||
free(command);
|
||||
|
Loading…
x
Reference in New Issue
Block a user