[sheepdog] [PATCH] check the return value of inet_ntop()

Liu Yuan namei.unix at gmail.com
Wed May 22 10:16:43 CEST 2013


On 05/21/2013 03:08 PM, MORITA Kazutaka wrote:
> Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
> ---
>  lib/net.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/net.c b/lib/net.c
> index 464ccb7..d3e8e91 100644
> --- a/lib/net.c
> +++ b/lib/net.c
> @@ -422,8 +422,9 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
>  
>  char *addr_to_str(char *str, int size, const uint8_t *addr, uint16_t port)
>  {
> -	int  af = AF_INET6;
> -	int  addr_start_idx = 0;
> +	int af = AF_INET6;
> +	int addr_start_idx = 0;
> +	const char *ret;
>  
>  	/* Find address family type */
>  	if (addr[12]) {
> @@ -435,7 +436,10 @@ char *addr_to_str(char *str, int size, const uint8_t *addr, uint16_t port)
>  			addr_start_idx = 12;
>  		}
>  	}
> -	inet_ntop(af, addr + addr_start_idx, str, size);
> +	ret = inet_ntop(af, addr + addr_start_idx, str, size);
> +	if (ret == NULL)
> +		panic("failed to convert addr to string, %m");
> +
>  	if (port) {
>  		int  len = strlen(str);
>  		snprintf(str + len, size - len, ":%d", port);
> 

Applied, thanks.

Yuan



More information about the sheepdog mailing list