From 6e7e58aa38ad478aeac7c8e0537c81fda459199e Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Mon, 24 Mar 2014 18:18:45 -0400 Subject: [PATCH] builtin should be returned const callers should never try to do any non-const operation with the builtin public suffix list. --- include/libpsl.h | 2 +- src/psl.c | 6 +++--- tests/test-is-public-builtin.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/libpsl.h b/include/libpsl.h index 894e125..c458226 100644 --- a/include/libpsl.h +++ b/include/libpsl.h @@ -64,7 +64,7 @@ psl_ctx_t * psl_load_file(const char *fname); psl_ctx_t * psl_load_fp(FILE *fp); -psl_ctx_t * +const psl_ctx_t * psl_builtin(void); int psl_is_public(const psl_ctx_t *psl, const char *domain); diff --git a/src/psl.c b/src/psl.c index 7e04326..01e654c 100644 --- a/src/psl.c +++ b/src/psl.c @@ -81,8 +81,8 @@ struct _psl_ctx_st { #include "suffixes.c" // references to this PSL will result in lookups to built-in data -static psl_ctx_t - _builtin_psl; +static const psl_ctx_t + _builtin_psl = { .suffixes = NULL, .suffix_exceptions = NULL, }; static _psl_vector_t *_vector_alloc(int max, int (*cmp)(const _psl_entry_t *, const _psl_entry_t *)) { @@ -380,7 +380,7 @@ psl_ctx_t *psl_load_fp(FILE *fp) } // return built-in PSL structure -psl_ctx_t *psl_builtin(void) +const psl_ctx_t *psl_builtin(void) { return &_builtin_psl; } diff --git a/tests/test-is-public-builtin.c b/tests/test-is-public-builtin.c index adc28d4..4a86036 100644 --- a/tests/test-is-public-builtin.c +++ b/tests/test-is-public-builtin.c @@ -70,7 +70,7 @@ static void test_psl(void) { "www.xn--czr694b", 1 }, }; unsigned it; - psl_ctx_t *psl; + const psl_ctx_t *psl; if (psl_global_init() == 0) { psl = psl_builtin();