[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] fix bug in print loadable builtin
From: |
Emanuele Torre |
Subject: |
[PATCH] fix bug in print loadable builtin |
Date: |
Mon, 2 May 2022 17:28:47 +0200 |
ansicstr() returns NULL when the string argument is the empty string, so
passing its return value to fprintf() will cause a segmentation fault.
That happened when one of the arguments was the empty string and the
`-r' option was not used.
example:
bash-5.1$ enable -f /usr/lib/bash/print print
bash-5.1$ (print '')
Segmentation fault (core dumped)
bash-5.1$ (print -r '')
bash-5.1$ (print a '' b)
Segmentation fault (core dumped)
---
examples/loadables/print.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/examples/loadables/print.c b/examples/loadables/print.c
index 0120dbf4..6be2778a 100644
--- a/examples/loadables/print.c
+++ b/examples/loadables/print.c
@@ -181,8 +181,11 @@ printargs (list, ofp)
for (sawc = 0, l = list; l; l = l->next)
{
ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, (int
*)0);
- fprintf (ofp, "%s", ostr);
- free (ostr);
+ if (ostr)
+ {
+ fprintf (ofp, "%s", ostr);
+ free (ostr);
+ }
if (sawc)
return (0);
if (l->next)
--
2.36.0
- [PATCH] fix bug in print loadable builtin,
Emanuele Torre <=