From fb7d3b4e38def0a870837e708326e9e779986945 Mon Sep 17 00:00:00 2001 From: Moritz Grimm Date: Mon, 1 Jun 2015 14:57:20 +0200 Subject: [PATCH] Check args prior to allocating resources --- src/metadata.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/metadata.c b/src/metadata.c index 8383b3f..b616db9 100644 --- a/src/metadata.c +++ b/src/metadata.c @@ -364,26 +364,22 @@ metadata_program(const char *program, int normalize) metadata_t *md; struct stat st; - md = metadata_create(program); - md->program = 1; - md->string = xstrdup(""); - if (stat(program, &st) == -1) { log_error("%s: %s", program, strerror(errno)); - metadata_free(&md); return (NULL); } if (st.st_mode & S_IWOTH) { log_error("%s: world writeable", program); - metadata_free(&md); return (NULL); } if (!(st.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH))) { log_error("%s: not an executable program", program); - metadata_free(&md); return (NULL); } + md = metadata_create(program); + md->program = 1; + md->string = xstrdup(""); md->normalize = normalize; return (md);