nsswitch: winbind_nss_aix: Remove all uses of strcpy.
authorJeremy Allison <jra@samba.org>
Wed, 16 Mar 2016 21:04:34 +0000 (14:04 -0700)
committerMartin Schwenke <martins@samba.org>
Tue, 22 Mar 2016 03:38:24 +0000 (04:38 +0100)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
nsswitch/winbind_nss_aix.c

index c5c223f4758817c106c0cdf32e8d1ab65e51df98..dc44db40ef96127a2f8863a60b7a516de5f74a40 100644 (file)
@@ -85,13 +85,15 @@ static void logit(const char *format, ...)
 #define STRCPY_RET(dest, src) \
 do { \
        if (strlen(src)+1 > sizeof(dest)) { errno = EINVAL; return -1; } \
-       strcpy(dest, src); \
+       strncpy(dest, src, sizeof(dest)); \
+       dest[sizeof(dest)-1] = '\0'; \
 } while (0)
 
 #define STRCPY_RETNULL(dest, src) \
 do { \
        if (strlen(src)+1 > sizeof(dest)) { errno = EINVAL; return NULL; } \
-       strcpy(dest, src); \
+       strncpy(dest, src, sizeof(dest)); \
+       dest[sizeof(dest)-1] = '\0'; \
 } while (0)
 
 
@@ -578,18 +580,21 @@ static attrval_t pwd_to_groupsids(struct passwd *pwd)
 {
        attrval_t r;
        char *s, *p;
+       size_t mlen;
 
        if ( (s = wb_aix_getgrset(pwd->pw_name)) == NULL ) {
                r.attr_flag = EINVAL;
                return r;
        }
 
-       if ( (p = malloc(strlen(s)+2)) == NULL ) {
+       mlen = strlen(s)+2;
+       if ( (p = malloc(mlen)) == NULL ) {
                r.attr_flag = ENOMEM;
                return r;
        }
 
-       strcpy(p, s);
+       strncpy(p, s, mlen);
+       p[mlen-1] = '\0';
        replace_commas(p);
        free(s);
 
@@ -855,7 +860,8 @@ static int wb_aix_normalize(char *longname, char *shortname)
        /* automatically cope with AIX 5.3 with longer usernames
           when it comes out */
        if (S_NAMELEN > strlen(longname)) {
-               strcpy(shortname, longname);
+               strncpy(shortname, longname, S_NAMELEN);
+               shortname[S_NAMELEN-1] = '\0';
                return 1;
        }