mirror of
https://github.com/swaywm/sway.git
synced 2024-11-05 16:03:11 +00:00
Merge pull request #2155 from ael-code/fix_output_command_failure
bugfix: avoid access after free
This commit is contained in:
commit
5222e14555
|
@ -3,6 +3,7 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
#include "sway/config.h"
|
#include "sway/config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
@ -71,21 +72,27 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
|
||||||
if (conf) {
|
if (conf) {
|
||||||
char *conf_path = dirname(conf);
|
char *conf_path = dirname(conf);
|
||||||
src = malloc(strlen(conf_path) + strlen(src) + 2);
|
src = malloc(strlen(conf_path) + strlen(src) + 2);
|
||||||
if (src) {
|
if (!src) {
|
||||||
sprintf(src, "%s/%s", conf_path, p.we_wordv[0]);
|
free(conf);
|
||||||
} else {
|
wordfree(&p);
|
||||||
wlr_log(L_ERROR,
|
wlr_log(L_ERROR,
|
||||||
"Unable to allocate background source");
|
"Unable to allocate resource: Not enough memory");
|
||||||
|
return cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to allocate resources");
|
||||||
}
|
}
|
||||||
|
sprintf(src, "%s/%s", conf_path, p.we_wordv[0]);
|
||||||
free(conf);
|
free(conf);
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "Unable to allocate background source");
|
wlr_log(L_ERROR, "Unable to allocate background source");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!src || access(src, F_OK) == -1) {
|
|
||||||
|
if (access(src, F_OK) == -1) {
|
||||||
|
struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output",
|
||||||
|
"Unable to access background file '%s': %s", src, strerror(errno));
|
||||||
|
free(src);
|
||||||
wordfree(&p);
|
wordfree(&p);
|
||||||
return cmd_results_new(CMD_INVALID, "output",
|
return cmd_res;
|
||||||
"Background file unreadable (%s).", src);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output->background = strdup(src);
|
output->background = strdup(src);
|
||||||
|
|
Loading…
Reference in a new issue