Message ID | 20240708210912.566-3-chipitsine@gmail.com |
---|---|
State | New |
Headers | show |
Series | handle strdup errors | expand |
On Mon, Jul 08, 2024 at 11:08:19PM +0200, Ilia Shipitsin wrote: > Signed-off-by: Ilia Shipitsin <chipitsine@gmail.com> > --- > sample/sample-plugins/defer/multi-auth.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/sample/sample-plugins/defer/multi-auth.c b/sample/sample-plugins/defer/multi-auth.c > index 2c482799..109fa40c 100644 > --- a/sample/sample-plugins/defer/multi-auth.c > +++ b/sample/sample-plugins/defer/multi-auth.c > @@ -206,9 +206,24 @@ openvpn_plugin_open_v3(const int v3structver, > if ((args->argv[4]) && !args->argv[5]) > { > context->authid = strdup(args->argv[1]); > + if (!context->authid) > + { > + plog(context, PLOG_ERR, "Out of memory"); > + goto error; > + } > context->test_deferred_auth = atoi_null0(args->argv[2]); > context->test_valid_user = strdup(args->argv[3]); > + if (!context->test_valid_user) > + { > + plog(context, PLOG_ERR, "Out of memory"); > + goto error; > + } > context->test_valid_pass = strdup(args->argv[4]); > + if (!context->test_valid_pass) > + { > + plog(context, PLOG_ERR, "Out of memory"); > + goto error; > + } > } > else > { A bit ugly. Might be nicer to combine the error handling into one if check, instead of doing separate ones for each call. But OTOH no need to overengineer sample code. So Acked-by: Frank Lichtenheld <frank@lichtenheld.com> Regards,
diff --git a/sample/sample-plugins/defer/multi-auth.c b/sample/sample-plugins/defer/multi-auth.c index 2c482799..109fa40c 100644 --- a/sample/sample-plugins/defer/multi-auth.c +++ b/sample/sample-plugins/defer/multi-auth.c @@ -206,9 +206,24 @@ openvpn_plugin_open_v3(const int v3structver, if ((args->argv[4]) && !args->argv[5]) { context->authid = strdup(args->argv[1]); + if (!context->authid) + { + plog(context, PLOG_ERR, "Out of memory"); + goto error; + } context->test_deferred_auth = atoi_null0(args->argv[2]); context->test_valid_user = strdup(args->argv[3]); + if (!context->test_valid_user) + { + plog(context, PLOG_ERR, "Out of memory"); + goto error; + } context->test_valid_pass = strdup(args->argv[4]); + if (!context->test_valid_pass) + { + plog(context, PLOG_ERR, "Out of memory"); + goto error; + } } else {
Signed-off-by: Ilia Shipitsin <chipitsine@gmail.com> --- sample/sample-plugins/defer/multi-auth.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)