Re: The bind command is broken in 6.1

Ethan A Merritt <[email protected]> Sat, 18 Jul 2026 00:04:52 -0700
Newsgroups gmane.comp.graphics.gnuplot.devel
Message-ID <CALUAmEvoajLbrmC5rb3kNzCwe5Z6RcA7_zvDnvTTH48=ww4+8g@mail.gmail.com>
--===============4833502815565905604==
Content-Type: multipart/alternative; boundary="000000000000d7719d0656dd4a84"

--000000000000d7719d0656dd4a84
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, Jul 16, 2026 at 9:47=E2=80=AFAM Juh=C3=A1sz P=C3=A9ter <peter.juhas=
[email protected]>
wrote:

>
>
> executive summary:
> the canonical form of the bind command (e.g. `bind a "replot"`) does
> not work, probably since 2024, because of changeset 96d580c508.
>

Yes.  My fault.  Fixed now.
Thanks for the report.

So here's the story.  I regularly run the full set of demos with saved
output
so that I can compare the plots produced before/after any code changes.
The tests can be run under valgrind or asan to detect memory access
violations. To the extent that the demos actually exercise all program
options
and the resulting code paths, it does a reasonable job of finding parsing
errors, run-time errors, memory leaks, and so on in addition to detecting
incorrectly generated plots.

Unfortunately these tests do not exercise all terminal-specific code, and
do not test mousing or other interactive use of the program.
So they did not, and could not, catch this breakage in the "bind" command.

If anyone has ideas of how to increase the coverage of automated testing,
please speak up.  It would also be helpful if you know of any program
options or plot modes that are not part of the demo collection, and hence
not tested.

 - Ethan




> explanation:
> Gnuplot is one of the few programs I still compile from source,
> recompiling rarely, usually only when I change computers or upgrade the
> OS. That's why I only noticed now that a company-internal analysis
> script that relies heavily on `bind` stopped working after recompiling
> the current gnuplot source.
>
> The simplest form of `bind`, e.g. `bind a "replot"`, as given in the
> manual, does not do anything, it just fails silently.
>
> I believe the breakage was introduced in commit 96d580c508,
> specifically this bit:
>
> @ -1037,8 +1037,7 @@ bind_command()
>         char *first =3D gp_input_line + token[c_token].start_index;
>         int size =3D strcspn(first, " \";");
>         lhs =3D gp_alloc(size + 1, "bind_command->lhs");
> -       strncpy(lhs, first, size);
> -       lhs[size] =3D '\0';
> +       safe_strncpy(lhs, first, size);
>         FPRINTF((stderr,"Got bind unquoted lhs =3D \"%s\"\n",lhs));
>         while (gp_input_line + token[c_token].start_index < first+size)
>             c_token++;
>
> `safe_strncpy` is aliased to `strlcpy`, if available, and I seem to
> have it, but in any case, this is not an equivalent change.
>
> In the case of a naked single-character first argument to bind, size
> will be 1 in the code above. `strlcpy` copies at most `size` (so, 1)
> bytes, and sets the last (that is, the only) byte to null.
>
> Then the code that wants to set up the binding receives an empty
> string, which causes it to silently fail.
>
> This incorrect behavior can be also seen with the command `bind RR
> "replot"`, which is nonsensical and should be an error, but instead it
> sets up the binding for "R".
>
> Luckily, the quoted case `bind "R" "replot"` still works.
>
> There may be other instances of this incorrect usage of safe_strncpy, I
> haven't checked.
>
> best regards,
>
> Peter Juhasz
>
>
> _______________________________________________
> gnuplot-beta mailing list
> [email protected]
> Membership management via:
> https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/=
gnuplot-beta__;!!K-Hz7m0Vt54!hwk5Sr7cG1SlpX05GVACsAMQf-E35prPcaVkLTXV_8BuQR=
ntHCZc_iqZwwDXW9GpogtRy8M-YMpd9o-wp5MdDT0$
>


--=20
Ethan A Merritt
Department of Biochemistry
University of Washington, Seattle

--000000000000d7719d0656dd4a84
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g=
mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Thu, Jul 16,=
 2026 at 9:47=E2=80=AFAM Juh=C3=A1sz P=C3=A9ter &lt;<a href=3D"mailto:peter=
[email protected]">[email protected]</a>&gt; wrote:<br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:=
1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
executive summary:<br>
the canonical form of the bind command (e.g. `bind a &quot;replot&quot;`) d=
oes<br>
not work, probably since 2024, because of changeset 96d580c508.<br></blockq=
uote><div><br></div><div>Yes.=C2=A0 My fault.=C2=A0 Fixed now.</div><div>Th=
anks for the report.</div><div><br></div><div>So here&#39;s the story.=C2=
=A0 I regularly run the full set of demos with saved output</div><div>so th=
at I can compare the plots produced before/after any code changes.</div><di=
v>The tests can be run under valgrind or asan to detect memory access</div>=
<div>violations.=C2=A0<span style=3D"background-color:transparent">To the e=
xtent that the demos actually exercise all program options</span></div><div=
><span style=3D"background-color:transparent">and the=C2=A0</span><span sty=
le=3D"background-color:transparent">resulting code paths, it does a reasona=
ble=C2=A0</span><span style=3D"background-color:transparent">job of finding=
=C2=A0</span><span style=3D"background-color:transparent">parsing</span></d=
iv><div><span style=3D"background-color:transparent">errors, run-time error=
s, memory leaks, and so on in addition to detecting</span></div><div><span =
style=3D"background-color:transparent">incorrectly generated plots.</span><=
/div><div><span style=3D"background-color:transparent"><br></span></div><di=
v><span style=3D"background-color:transparent">Unfortunately these tests do=
 not exercise all terminal-specific code, and</span></div><div><span style=
=3D"background-color:transparent">do not test mousing or other interactive =
use of the program.</span></div><div><span style=3D"background-color:transp=
arent">So they did not, and could not, catch this breakage in the &quot;bin=
d&quot; command.</span></div><div><span style=3D"background-color:transpare=
nt"><br></span></div><div><span style=3D"background-color:transparent">If a=
nyone has ideas of how to increase the coverage of automated testing,</span=
></div><div><span style=3D"background-color:transparent">please speak up.=
=C2=A0 It would also be helpful if you know of any program</span></div><div=
><span style=3D"background-color:transparent">options or plot modes that ar=
e not part of the demo collection, and hence</span></div><div><span style=
=3D"background-color:transparent">not tested.</span></div><div><span style=
=3D"background-color:transparent"><br></span></div><div><span style=3D"back=
ground-color:transparent">=C2=A0- Ethan=C2=A0 =C2=A0</span></div><div><br><=
/div><div><br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">
explanation:<br>
Gnuplot is one of the few programs I still compile from source,<br>
recompiling rarely, usually only when I change computers or upgrade the<br>
OS. That&#39;s why I only noticed now that a company-internal analysis<br>
script that relies heavily on `bind` stopped working after recompiling<br>
the current gnuplot source.<br>
<br>
The simplest form of `bind`, e.g. `bind a &quot;replot&quot;`, as given in =
the<br>
manual, does not do anything, it just fails silently.<br>
<br>
I believe the breakage was introduced in commit 96d580c508,<br>
specifically this bit:<br>
<br>
@ -1037,8 +1037,7 @@ bind_command()<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 char *first =3D gp_input_line + token[c_token].=
start_index;<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 int size =3D strcspn(first, &quot; \&quot;;&quo=
t;);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 lhs =3D gp_alloc(size + 1, &quot;bind_command-&=
gt;lhs&quot;);<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0strncpy(lhs, first, size);<br>
-=C2=A0 =C2=A0 =C2=A0 =C2=A0lhs[size] =3D &#39;\0&#39;;<br>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0safe_strncpy(lhs, first, size);<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 FPRINTF((stderr,&quot;Got bind unquoted lhs =3D=
 \&quot;%s\&quot;\n&quot;,lhs));<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 while (gp_input_line + token[c_token].start_ind=
ex &lt; first+size)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 c_token++;<br>
<br>
`safe_strncpy` is aliased to `strlcpy`, if available, and I seem to<br>
have it, but in any case, this is not an equivalent change.<br>
<br>
In the case of a naked single-character first argument to bind, size<br>
will be 1 in the code above. `strlcpy` copies at most `size` (so, 1)<br>
bytes, and sets the last (that is, the only) byte to null.<br>
<br>
Then the code that wants to set up the binding receives an empty<br>
string, which causes it to silently fail.<br>
<br>
This incorrect behavior can be also seen with the command `bind RR<br>
&quot;replot&quot;`, which is nonsensical and should be an error, but inste=
ad it<br>
sets up the binding for &quot;R&quot;.<br>
<br>
Luckily, the quoted case `bind &quot;R&quot; &quot;replot&quot;` still work=
s.<br>
<br>
There may be other instances of this incorrect usage of safe_strncpy, I<br>
haven&#39;t checked.<br>
<br>
best regards,<br>
<br>
Peter Juhasz<br>
<br>
<br>
_______________________________________________<br>
gnuplot-beta mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">gnu=
[email protected]</a><br>
Membership management via: <a href=3D"https://urldefense.com/v3/__https://l=
ists.sourceforge.net/lists/listinfo/gnuplot-beta__;!!K-Hz7m0Vt54!hwk5Sr7cG1=
SlpX05GVACsAMQf-E35prPcaVkLTXV_8BuQRntHCZc_iqZwwDXW9GpogtRy8M-YMpd9o-wp5MdD=
T0$" rel=3D"noreferrer" target=3D"_blank">https://urldefense.com/v3/__https=
://lists.sourceforge.net/lists/listinfo/gnuplot-beta__;!!K-Hz7m0Vt54!hwk5Sr=
7cG1SlpX05GVACsAMQf-E35prPcaVkLTXV_8BuQRntHCZc_iqZwwDXW9GpogtRy8M-YMpd9o-wp=
5MdDT0$</a> <br>
</blockquote></div><div><br clear=3D"all"></div><div><br></div><span class=
=3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s=
ignature"><div dir=3D"ltr"><span style=3D"font-family:monospace"><span styl=
e=3D"color:rgb(0,0,0)">Ethan A Merritt
</span><br>Department of Biochemistry<br>University of Washington, Seattle<=
br>
<br></span></div></div></div>

--000000000000d7719d0656dd4a84--


--===============4833502815565905604==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============4833502815565905604==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gnuplot-beta mailing list
[email protected]
Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-beta

--===============4833502815565905604==--