Patches to review

Richard Kimberly Heck rikiheck at lyx.org
Tue Nov 24 21:59:16 UTC 2020


On 11/24/20 4:29 PM, Yuriy Skalko wrote:
> As for the patch 5, these null pointer dereferences happen even on 
> opening LyX manuals. It is undefined behavior even if it doesn't crash 
> LyX. Most likely should be fixed somewhere instead of just checking.
> From 234bfe70c1e2766d856257aebe7eaad8836f5976 Mon Sep 17 00:00:00 2001
> From: Yuriy Skalko <yuriy.skalko at gmail.com>
> Date: Tue, 24 Nov 2020 22:59:24 +0200
> Subject: [PATCH 5/5] Add nullptr checks
>
> ---
>  src/mathed/InsetMathMacro.cpp | 2 ++
>  src/mathed/InsetMathNest.cpp  | 2 ++
>  2 files changed, 4 insertions(+)
>
> diff --git a/src/mathed/InsetMathMacro.cpp b/src/mathed/InsetMathMacro.cpp
> index 881a3c8194..bc9ee9d318 100644
> --- a/src/mathed/InsetMathMacro.cpp
> +++ b/src/mathed/InsetMathMacro.cpp
> @@ -307,6 +307,8 @@ InsetMathMacro::InsetMathMacro(Buffer * buf, 
> docstring const & name)
>  InsetMathMacro::InsetMathMacro(InsetMathMacro const & that)
>      : InsetMathNest(that), d(new Private(*that.d))
>  {
> +    if (!that.buffer_)
> +        LYXERR0("Passing nullptr as reference");
>      setBuffer(*that.buffer_);
>      d->updateChildren(this);
>  }

This one comes from initSymbols, where we're initializing the list of 
global math macros. These are not associated with a Buffer, hence the 
nullptr that is passed. For now, I think we can just check and call 
setBuffer only if it's not null. I'll commit that.

Longer term, this is coming from the MacroData stuff, which I think I 
see how to simplify. Then this problem will actually go away.


> diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
> index c085439017..2c5f6b35a0 100644
> --- a/src/mathed/InsetMathNest.cpp
> +++ b/src/mathed/InsetMathNest.cpp
> @@ -85,6 +85,8 @@ using cap::selClearOrDel;
>  InsetMathNest::InsetMathNest(Buffer * buf, idx_type nargs)
>      : InsetMath(buf), cells_(nargs), lock_(false)
>  {
> +    if (!buf)
> +        LYXERR0("Passing nullptr as reference");
>      setBuffer(*buf);
>  }
>
> -- 
> 2.28.0.windows.1
>

>
> Yuriy
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lyx.org/pipermail/lyx-devel/attachments/20201124/31a5e898/attachment-0001.html>


More information about the lyx-devel mailing list