test: hostname - test that hostname is truly initialized

Fixes CID CID 1299638 (use after free).
This commit is contained in:
Tom Gundersen
2015-05-25 23:10:26 +02:00
parent cc9fce6554
commit e136009df2
+7
View File
@@ -563,24 +563,31 @@ static void test_read_hostname_config(void) {
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(streq(hostname, "foo"));
free(hostname);
hostname = NULL;
/* with comment */
write_string_file(path, "# comment\nfoo");
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
free(hostname);
hostname = NULL;
/* with comment and extra whitespace */
write_string_file(path, "# comment\n\n foo ");
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foo"));
free(hostname);
hostname = NULL;
/* cleans up name */
write_string_file(path, "!foo/bar.com");
assert_se(read_hostname_config(path, &hostname) == 0);
assert_se(hostname);
assert_se(streq(hostname, "foobar.com"));
free(hostname);
hostname = NULL;
/* no value set */
hostname = (char*) 0x1234;