Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | From 08abfcd923e9f37d1902db26771b1dc6731eb265 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jiri Popelka <jpopelka@redhat.com> |
| 3 | Date: Fri, 27 Sep 2013 18:40:06 +0200 |
| 4 | Subject: [PATCH 1/1] lib/inet6.c:INET6_rresolve() - various fixes |
| 5 | |
| 6 | 1) Fall-back to numeric address if getnameinfo fails. |
| 7 | Reverse lookup is not mandatory, therefore its fail |
| 8 | is not an error. Just return numeric address in that case. |
| 9 | This makes netstat/route show IPv6 address instead of |
| 10 | [UNKNOWN] in case of DNS problems. |
| 11 | |
| 12 | 2) Pass length of 'name' buffer into function. |
| 13 | 'name' is a pointer and therefore sizeof(name) |
| 14 | returns size of pointer and not size of the buffer. |
| 15 | see http://stackoverflow.com/questions/14298710/c-pointers-and-arrays-sizeof-operator |
| 16 | The sizeof() usage was added with commit 604785adc, |
| 17 | so I checked all the other changes in that commit |
| 18 | and they seem to be OK. |
| 19 | |
| 20 | 3) remove unused 's' variable |
| 21 | |
| 22 | Upstream-Status: Pending |
| 23 | |
| 24 | Signed-off-by: Shan Hai <shan.hai@windriver.com> |
| 25 | Signed-off-by: Jianchuan Wang <jianchuan.wang@windriver.com> |
| 26 | --- |
| 27 | lib/inet6.c | 21 ++++++++++----------- |
| 28 | 1 file changed, 10 insertions(+), 11 deletions(-) |
| 29 | |
| 30 | diff --git a/lib/inet6.c b/lib/inet6.c |
| 31 | index 9a484a0..2a9c459 100644 |
| 32 | --- a/lib/inet6.c |
| 33 | +++ b/lib/inet6.c |
| 34 | @@ -84,10 +84,9 @@ static int INET6_resolve(char *name, struct sockaddr_in6 *sin6) |
| 35 | #endif |
| 36 | |
| 37 | |
| 38 | -static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric) |
| 39 | +static int INET6_rresolve(char *name, size_t namelen, |
| 40 | + struct sockaddr_in6 *sin6, int numeric) |
| 41 | { |
| 42 | - int s; |
| 43 | - |
| 44 | /* Grmpf. -FvK */ |
| 45 | if (sin6->sin6_family != AF_INET6) { |
| 46 | #ifdef DEBUG |
| 47 | @@ -98,21 +97,20 @@ static int INET6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric) |
| 48 | return (-1); |
| 49 | } |
| 50 | if (numeric & 0x7FFF) { |
| 51 | - inet_ntop( AF_INET6, &sin6->sin6_addr, name, 80); |
| 52 | + inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen); |
| 53 | return (0); |
| 54 | } |
| 55 | if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { |
| 56 | if (numeric & 0x8000) |
| 57 | - strcpy(name, "default"); |
| 58 | + safe_strncpy(name, "default", namelen); |
| 59 | else |
| 60 | - strcpy(name, "[::]"); |
| 61 | + safe_strncpy(name, "[::]", namelen); |
| 62 | return (0); |
| 63 | } |
| 64 | |
| 65 | - if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), |
| 66 | - name, 255 /* !! */ , NULL, 0, 0))) { |
| 67 | - fputs("getnameinfo failed\n", stderr); |
| 68 | - return -1; |
| 69 | + if (getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), |
| 70 | + name, namelen , NULL, 0, 0)) { |
| 71 | + inet_ntop( AF_INET6, &sin6->sin6_addr, name, namelen); |
| 72 | } |
| 73 | return (0); |
| 74 | } |
| 75 | @@ -143,7 +141,8 @@ static char *INET6_sprint(struct sockaddr *sap, int numeric) |
| 76 | |
| 77 | if (sap->sa_family == 0xFFFF || sap->sa_family == 0) |
| 78 | return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); |
| 79 | - if (INET6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0) |
| 80 | + if (INET6_rresolve(buff, sizeof(buff), |
| 81 | + (struct sockaddr_in6 *) sap, numeric) != 0) |
| 82 | return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); |
| 83 | return (fix_v4_address(buff, &((struct sockaddr_in6 *)sap)->sin6_addr)); |
| 84 | } |
| 85 | -- |
| 86 | 1.8.5.2.233.g932f7e4 |
| 87 | |