Skip to content

Commit

Permalink
Merge pull request #111 from jhrozek/emptyhostname
Browse files Browse the repository at this point in the history
obj: Be more defensive about an empty host name
  • Loading branch information
jhrozek committed Jan 9, 2018
2 parents 7ec613e + 3c0d03a commit cbca30f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/pam_hbac_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ ph_get_host(struct pam_hbac_ctx *ctx,
return EINVAL;
}

if (strlen(hostname) == 0) {
logger(ctx->pamh, LOG_NOTICE, "Host name is empty\n");
return ENOENT;
}

ret = asprintf(&host_filter, "%s=%s",
ph_host_attrs[PH_MAP_HOST_FQDN], hostname);
if (ret < 0) {
Expand Down
16 changes: 16 additions & 0 deletions src/tests/obj_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ test_ph_host_no_fqdn(void **state)
assert_null(host);
}

static void
test_ph_host_name_empty(void **state)
{
int ret;
struct pam_hbac_ctx ph_ctx;
const char *hostname = "";
struct ph_entry *host = NULL;

memset(&ph_ctx, 0, sizeof(ph_ctx));

ret = ph_get_host(&ph_ctx, hostname, &host);
assert_int_equal(ret, ENOENT);
assert_null(host);
}

static void
test_ph_svc(void **state)
{
Expand Down Expand Up @@ -382,6 +397,7 @@ main(void)
cmocka_unit_test(test_ph_host_multiple),
cmocka_unit_test(test_ph_host_srch_fail),
cmocka_unit_test(test_ph_host_no_fqdn),
cmocka_unit_test(test_ph_host_name_empty),
cmocka_unit_test(test_ph_svc),
cmocka_unit_test(test_ph_svc_multiple),
cmocka_unit_test(test_ph_svc_srch_fail),
Expand Down

0 comments on commit cbca30f

Please sign in to comment.