From: Phil Sutter <phil@nwl.cc>
To: Ilia Kashintsev <ilia.kashintsev@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: Null dereference in ebtables-restore.c
Date: Thu, 18 Dec 2025 14:53:11 +0100 [thread overview]
Message-ID: <aUQHRzlp0dg5KZ_x@orbyte.nwl.cc> (raw)
In-Reply-To: <CAF6ebR7PoBEpheSSjsSZqxUJh3yPeh1KjGTuGWsG0KwbuhJKMQ@mail.gmail.com>
Hi,
On Thu, Dec 18, 2025 at 04:17:39PM +0300, Ilia Kashintsev wrote:
> Hello maintainers! I have found a SEGV in ebtables-restore.c
>
> It occurs on the following line:
> *strchr(cmdline, '\n') = '\0';
>
> If '\n' is not present in cmdline, then the result of strchr() is NULL
> with a dereference attempt afterwards.
Thanks for the detailed report!
[...]
> Suggested fix:
>
> Check strchr() result before trying to dereference it.
>
> diff --git a/ebtables-restore.c b/ebtables-restore.c
> index bb4d0cf..c97364b 100644
> --- a/ebtables-restore.c
> +++ b/ebtables-restore.c
> @@ -76,7 +76,9 @@ int main(int argc_, char *argv_[])
> line++;
> if (*cmdline == '#' || *cmdline == '\n')
> continue;
> - *strchr(cmdline, '\n') = '\0';
> + char *new_line = strchr(cmdline, '\n');
> + if (new_line)
> + *new_line = '\0';
> if (*cmdline == '*') {
> if (table_nr != -1) {
> ebt_deliver_table(&replace[table_nr]);
How about simply using strchrnul():
--- a/ebtables-restore.c
+++ b/ebtables-restore.c
@@ -17,6 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -76,7 +77,7 @@ int main(int argc_, char *argv_[])
line++;
if (*cmdline == '#' || *cmdline == '\n')
continue;
- *strchr(cmdline, '\n') = '\0';
+ *strchrnul(cmdline, '\n') = '\0';
if (*cmdline == '*') {
if (table_nr != -1) {
ebt_deliver_table(&replace[table_nr]);
Cheers, Phil
next prev parent reply other threads:[~2025-12-18 13:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 13:17 Null dereference in ebtables-restore.c Ilia Kashintsev
2025-12-18 13:53 ` Phil Sutter [this message]
2025-12-20 21:06 ` Pablo Neira Ayuso
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=aUQHRzlp0dg5KZ_x@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=ilia.kashintsev@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox