[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] [PATCH] Verify name is allocated in hostname.c/parse_arg
From: |
Omer Anson |
Subject: |
[bug-inetutils] [PATCH] Verify name is allocated in hostname.c/parse_args |
Date: |
Mon, 19 Jun 2017 23:48:49 +0300 |
When calling parse_args, hostname assumes that a pointer is always
returned. However, if the input file contains only comments, and the
last line does not end with a newline, then parse_args can return NULL.
This happens because getline returns the number of characters read, and
sets the EOF flag on the file. Since it is a comment, the block
allocating 'name' is not entered, and 'name' remains NULL. The loops
exits since the EOF flag was set.
This change adds a test at the end of parse_args that exits if name was
not allocated, i.e. if name is still NULL.
---
src/hostname.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/hostname.c b/src/hostname.c
index e6a90f7..84d0444 100644
--- a/src/hostname.c
+++ b/src/hostname.c
@@ -416,5 +416,7 @@ parse_file (const char *const file_name)
free (buffer);
fclose (file);
+ if (name == NULL)
+ error(EXIT_FAILURE, 0, "parse_file");
return name;
}
--
2.4.11