NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/48585: Set errno if return is NULL in inet_ntop.c



>Number:         48585
>Category:       lib
>Synopsis:       Set errno if return is NULL in inet_ntop.c
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 10 11:40:00 +0000 2014
>Originator:     Henning Petersen
>Release:        NetBSD-current
>Organization:
>Environment:
>Description:
Set errno if return is NULL in inet_ntop.c .
Test if inet_ntop4 is NULL in inet_ntop6 .
>How-To-Repeat:

>Fix:
diff -u -r1.9 inet_ntop.c
--- lib/libc/inet/inet_ntop.c   20 Mar 2012 17:08:13 -0000      1.9
+++ lib/libc/inet/inet_ntop.c   10 Feb 2014 07:23:16 -0000
@@ -188,8 +188,10 @@
                }
                /* Are we following an initial run of 0x00s or any real hex? */
                if (i != 0) {
-                       if (tp + 1 >= ep)
+                       if (tp + 1 >= ep) {
+                               errno = ENOSPC;
                                return (NULL);
+                       }
                        *tp++ = ':';
                }
                /* Is this address an encapsulated IPv4? */
@@ -197,25 +199,33 @@
                    (best.len == 6 ||
                    (best.len == 7 && words[7] != 0x0001) ||
                    (best.len == 5 && words[5] == 0xffff))) {
-                       if (!inet_ntop4(src+12, tp, (socklen_t)(ep - tp)))
+                       if (inet_ntop4(src+12, tp, (socklen_t)(ep - tp))==NULL){
+                               errno = ENOSPC;
                                return (NULL);
+                       }
                        tp += strlen(tp);
                        break;
                }
                advance = snprintf(tp, (size_t)(ep - tp), "%x", words[i]);
-               if (advance <= 0 || advance >= ep - tp)
+               if (advance <= 0 || advance >= ep - tp) {
+                       errno = ENOSPC;
                        return (NULL);
+               }
                tp += advance;
        }
        /* Was it a trailing run of 0x00's? */
        if (best.base != -1 && (best.base + best.len) == 
            (NS_IN6ADDRSZ / NS_INT16SZ)) {
-               if (tp + 1 >= ep)
+               if (tp + 1 >= ep) {
+                       errno = ENOSPC;
                        return (NULL);
+               }
                *tp++ = ':';
        }
-       if (tp + 1 >= ep)
+       if (tp + 1 >= ep) {
+               errno = ENOSPC;
                return (NULL);
+       }
        *tp++ = '\0';
 
        /*



Home | Main Index | Thread Index | Old Index