Re: [Nbd] [PATCH] nbd-server: handle port number string conversion errors
- To: Tuomas Räsänen <tuomasjjrasanen@...1261...>
- Cc: nbd-general@lists.sourceforge.net
- Subject: Re: [Nbd] [PATCH] nbd-server: handle port number string conversion errors
- From: Wouter Verhelst <w@...112...>
- Date: Sat, 26 Jan 2013 17:15:14 +0100
- Message-id: <20130126161514.GB10510@...3...>
- In-reply-to: <bf531f3e846de5db8607b6b2bafa7f105b5fd928.1359059293.git.tuomasjjrasanen@...1261...>
- References: <bf531f3e846de5db8607b6b2bafa7f105b5fd928.1359059293.git.tuomasjjrasanen@...1261...>
Thanks, applied (earlier today, actually, but I forgot to confirm here :-)
On Thu, Jan 24, 2013 at 10:43:22PM +0200, Tuomas Räsänen wrote:
> g_strdup_printf() tries to allocate a string large enough to hold the
> string representation of the passed value and coverts the value to
> string. It returns NULL if memory allocation fails, or some other error
> occurs. Previously, NULL was interpreted as "modern style socket not
> needed for this export" by returning zero to the caller, which was
> utterly wrong.
>
> Signed-off-by: Tuomas Räsänen <tuomasjjrasanen@...1261...>
> ---
> nbd-server.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/nbd-server.c b/nbd-server.c
> index feb0ca6..69ee2a4 100644
> --- a/nbd-server.c
> +++ b/nbd-server.c
> @@ -2408,9 +2408,14 @@ int setup_serve(SERVER *const serve, GError **const gerror) {
> hints.ai_socktype = SOCK_STREAM;
> hints.ai_family = serve->socket_family;
>
> - port = g_strdup_printf ("%d", serve->port);
> - if (port == NULL)
> - return 0;
> + port = g_strdup_printf("%d", serve->port);
> + if (!port) {
> + g_set_error(gerror, NBDS_ERR, NBDS_ERR_SYS,
> + "failed to open an export socket: "
> + "failed to convert a port number to a string: %s",
> + strerror(errno));
> + goto out;
> + }
>
> e = getaddrinfo(serve->listenaddr,port,&hints,&ai);
>
> --
> 1.7.10.4
>
>
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnnow-d2d
> _______________________________________________
> Nbd-general mailing list
> Nbd-general@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nbd-general
--
Copyshops should do vouchers. So that next time some bureaucracy requires you
to mail a form in triplicate, you can mail it just once, add a voucher, and
save on postage.
Reply to: