diff mbox series

[1/4] libmultipath: don't print garbage keywords

Message ID 1665525183-27377-2-git-send-email-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series remove dangerous cleanup __attribute__ uses | expand

Commit Message

Benjamin Marzinski Oct. 11, 2022, 9:53 p.m. UTC
If snprint_keyword() failed to correctly set up sbuf, don't print it.
Instead, return an error.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmpathutil/parser.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Martin Wilck Oct. 21, 2022, 7:05 a.m. UTC | #1
On Tue, 2022-10-11 at 16:53 -0500, Benjamin Marzinski wrote:
> If snprint_keyword() failed to correctly set up sbuf, don't print it.
> Instead, return an error.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

> ---
>  libmpathutil/parser.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c
> index 014d9b83..8d3ac53a 100644
> --- a/libmpathutil/parser.c
> +++ b/libmpathutil/parser.c
> @@ -152,7 +152,7 @@ int
>  snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword
> *kw,
>                 const void *data)
>  {
> -       int r;
> +       int r = 0;
>         char *f;
>         struct config *conf;
>         STRBUF_ON_STACK(sbuf);
> @@ -190,8 +190,10 @@ snprint_keyword(struct strbuf *buff, const char
> *fmt, struct keyword *kw,
>                 }
>         } while (*fmt++);
>  out:
> -       return __append_strbuf_str(buff, get_strbuf_str(&sbuf),
> -                                  get_strbuf_len(&sbuf));
> +       if (r >= 0)
> +               r = __append_strbuf_str(buff, get_strbuf_str(&sbuf),
> +                                       get_strbuf_len(&sbuf));
> +       return r;
>  }
>  
>  static const char quote_marker[] = { '\0', '"', '\0' };

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/libmpathutil/parser.c b/libmpathutil/parser.c
index 014d9b83..8d3ac53a 100644
--- a/libmpathutil/parser.c
+++ b/libmpathutil/parser.c
@@ -152,7 +152,7 @@  int
 snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw,
 		const void *data)
 {
-	int r;
+	int r = 0;
 	char *f;
 	struct config *conf;
 	STRBUF_ON_STACK(sbuf);
@@ -190,8 +190,10 @@  snprint_keyword(struct strbuf *buff, const char *fmt, struct keyword *kw,
 		}
 	} while (*fmt++);
 out:
-	return __append_strbuf_str(buff, get_strbuf_str(&sbuf),
-				   get_strbuf_len(&sbuf));
+	if (r >= 0)
+		r = __append_strbuf_str(buff, get_strbuf_str(&sbuf),
+					get_strbuf_len(&sbuf));
+	return r;
 }
 
 static const char quote_marker[] = { '\0', '"', '\0' };