Changeset 51c48bf in rtems-libbsd


Ignore:
Timestamp:
Oct 31, 2013, 8:51:36 AM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, afaeccc05a556f6aa25ba044a7e49d6aa634a59e, freebsd-9.3, master
Children:
1f6caf3
Parents:
56e9de9
git-author:
Sebastian Huber <sebastian.huber@…> (10/31/13 08:51:36)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/31/13 12:18:49)
Message:

IFCONFIG(8): Avoid write to const string

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freebsd/sbin/ifconfig/af_inet6.c

    r56e9de9 r51c48bf  
    3939
    4040#include <err.h>
     41#include <errno.h>
    4142#include <stdio.h>
    4243#include <stdlib.h>
     
    339340
    340341static void
    341 in6_getaddr(const char *s, int which)
     342in6_getaddr(const char *cs, int which)
    342343{
    343344        struct sockaddr_in6 *sin = sin6tab[which];
    344345        struct addrinfo hints, *res;
    345346        int error = -1;
    346 
     347        char s[64];
     348        size_t slen = strlen(cs);
     349
     350        if (slen < sizeof(s) - 1 ) {
     351                memcpy(s, cs, slen + 1);
     352        } else {
     353                error = ENAMETOOLONG;
     354                goto done;
     355        }
    347356        newaddr &= 1;
    348357
     
    365374                error = getaddrinfo(s, NULL, &hints, &res);
    366375        }
     376done:
    367377        if (error != 0) {
    368                 if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
    369                         errx(1, "%s: bad value", s);
     378                if (inet_pton(AF_INET6, cs, &sin->sin6_addr) != 1)
     379                        errx(1, "%s: bad value", cs);
    370380        } else
    371381                bcopy(res->ai_addr, sin, res->ai_addrlen);
Note: See TracChangeset for help on using the changeset viewer.