From: Florian Westphal <fw@strlen.de>
To: Corubba Smith <corubba@gmx.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH ulogd2,v2 3/6] ulogd: raise error on unknown config key
Date: Wed, 12 Mar 2025 16:21:54 +0100 [thread overview]
Message-ID: <20250312152154.GA28069@breakpoint.cc> (raw)
In-Reply-To: <e3965ebb-b9f9-46ce-87e5-4960405dbe35@gmx.de>
Corubba Smith <corubba@gmx.de> wrote:
> Until a6fbeb96e889 ("new configuration file syntax (Magnus Boden)")
> this was already caught, and the enum member is still present.
>
> Check if the for loop worked throught the whole array without hitting a
> matching config option, and return with the unknown key error code.
> Because there is no existing config_entry struct with that unknwon key
> to use with the established config_errce pointer, allocate a new struct.
> This potentially creates a memory leak if that config_entry is never
> freed again, but for me that is acceptable is this rare case.
>
> Since the memory allocation for the struct can fail, also reuse the old
> out-of-memory error to indicate that.
>
> Signed-off-by: Corubba Smith <corubba@gmx.de>
> ---
> Changes in v2:
> - Reduce indentation of case statements (Florian Westphal)
>
> src/conffile.c | 11 +++++++++++
> src/ulogd.c | 2 ++
> 2 files changed, 13 insertions(+)
>
> diff --git a/src/conffile.c b/src/conffile.c
> index cc5552c..7b9fb0f 100644
> --- a/src/conffile.c
> +++ b/src/conffile.c
> @@ -236,6 +236,17 @@ int config_parse_file(const char *section, struct config_keyset *kset)
> break;
> }
> pr_debug("parse_file: exiting main loop\n");
> +
> + if (i == kset->num_ces) {
> + config_errce = calloc(1, sizeof(struct config_entry));
> + if (config_errce == NULL) {
> + err = -ERROOM;
> + goto cpf_error;
> + }
> + strncpy(&config_errce->key[0], wordbuf, CONFIG_KEY_LEN - 1);
This raises a bogus compiler warning for me:
conffile.c:246:25: warning: '__builtin_strncpy' output may be truncated copying 30 bytes from a string of length 254 [-Wstringop-truncation]
246 | strncpy(config_errce->key, wordbuf, sizeof(config_errce->key));
What do you make of this?
- strncpy(&config_errce->key[0], wordbuf, CONFIG_KEY_LEN - 1);
+ snprintf(config_errce->key, sizeof(config_errce->key), "%s", wordbuf);
next prev parent reply other threads:[~2025-03-12 15:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-12 14:52 [PATCH ulogd2,v2 1/6] ulogd: add ulogd_parse_configfile public function Corubba Smith
2025-03-12 14:53 ` [PATCH ulogd2,v2 2/6] all: use config_parse_file function in all plugins Corubba Smith
2025-03-12 14:54 ` [PATCH ulogd2,v2 3/6] ulogd: raise error on unknown config key Corubba Smith
2025-03-12 15:21 ` Florian Westphal [this message]
2025-03-12 18:48 ` Corubba Smith
2025-03-12 18:55 ` Florian Westphal
2025-03-12 14:55 ` [PATCH ulogd2,v2 4/6] ulogd: improve integer option parsing Corubba Smith
2025-03-12 14:55 ` [PATCH ulogd2,v2 5/6] ulogd: provide default configure implementation Corubba Smith
2025-03-12 14:56 ` [PATCH ulogd2,v2 6/6] all: remove trivial configure hooks Corubba Smith
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250312152154.GA28069@breakpoint.cc \
--to=fw@strlen.de \
--cc=corubba@gmx.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.