From ce3d7acf2d2d5cedeb0bd7bf108c055bb12cb00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 11 Jun 2019 08:32:28 +0300 Subject: [PATCH] Fix maxavrocheck path processing A null path could be given if realpath failed to resolve the name. This hides the actual reason of the failure making it harder to resolve it. --- avro/maxavrocheck.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/avro/maxavrocheck.c b/avro/maxavrocheck.c index e5951f3d2..90827ff02 100644 --- a/avro/maxavrocheck.c +++ b/avro/maxavrocheck.c @@ -120,8 +120,7 @@ int check_file(const char* filename) return rval; } -static struct option long_options[] = -{ +static struct option long_options[] = { {"verbose", no_argument, 0, 'v'}, {"dump", no_argument, 0, 'd'}, {"from", no_argument, 0, 'f'}, @@ -170,10 +169,14 @@ int main(int argc, char** argv) } int rval = 0; - char pathbuf[PATH_MAX + 1]; + for (int i = optind; i < argc; i++) { - if (check_file(realpath(argv[i], pathbuf))) + char pathbuf[PATH_MAX + 1]; + snprintf(pathbuf, sizeof(pathbuf), "%s", argv[i]); + realpath(argv[i], pathbuf); + + if (check_file(pathbuf)) { fprintf(stderr, "Failed to process file: %s\n", argv[i]); rval = 1;