Author: ngie
Date: Sat Dec  3 16:52:40 2016
New Revision: 309482
URL: https://svnweb.freebsd.org/changeset/base/309482

Log:
  MFC r299704:
  r299704 (by vangyzen):
  
  iconvctl(3): remove superfluous NULL pointer tests
  
  convname and dst are guaranteed to be non-NULL by iconv_open(3).
  src is an array. Remove these tests for NULL pointers.
  While I'm here, eliminate a strlcpy with a correct but suspicious-looking
  calculation for the third parameter (i.e. not a simple sizeof).
  Compare the strings in-place instead of copying.
  
  Found by:     bdrewery
  Found by:     Coverity
  CID:          1130050, 1130056

Added:
  stable/10/lib/libc/tests/iconv/
     - copied from r299704, head/lib/libc/tests/iconv/
Modified:
  stable/10/etc/mtree/BSD.tests.dist
  stable/10/lib/libc/iconv/bsd_iconv.c
  stable/10/lib/libc/tests/Makefile
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/etc/mtree/BSD.tests.dist
==============================================================================
--- stable/10/etc/mtree/BSD.tests.dist  Sat Dec  3 16:02:53 2016        
(r309481)
+++ stable/10/etc/mtree/BSD.tests.dist  Sat Dec  3 16:52:40 2016        
(r309482)
@@ -99,6 +99,8 @@
                 data
                 ..
             ..
+            iconv
+            ..
             inet
             ..
             locale

Modified: stable/10/lib/libc/iconv/bsd_iconv.c
==============================================================================
--- stable/10/lib/libc/iconv/bsd_iconv.c        Sat Dec  3 16:02:53 2016        
(r309481)
+++ stable/10/lib/libc/iconv/bsd_iconv.c        Sat Dec  3 16:52:40 2016        
(r309482)
@@ -259,8 +259,9 @@ __bsd_iconvctl(iconv_t cd, int request, 
        struct _citrus_iconv *cv;
        struct iconv_hooks *hooks;
        const char *convname;
-       char src[PATH_MAX], *dst;
+       char *dst;
        int *i;
+       size_t srclen;
 
        cv = (struct _citrus_iconv *)(void *)cd;
        hooks = (struct iconv_hooks *)argument;
@@ -275,12 +276,9 @@ __bsd_iconvctl(iconv_t cd, int request, 
        case ICONV_TRIVIALP:
                convname = cv->cv_shared->ci_convname;
                dst = strchr(convname, '/');
-
-               strlcpy(src, convname, dst - convname + 1);
+               srclen = dst - convname;
                dst++;
-               if ((convname == NULL) || (src == NULL) || (dst == NULL))
-                       return (-1);
-               *i = strcmp(src, dst) == 0 ? 1 : 0;
+               *i = (srclen == strlen(dst)) && !memcmp(convname, dst, srclen);
                return (0);
        case ICONV_GET_TRANSLITERATE:
                *i = 1;

Modified: stable/10/lib/libc/tests/Makefile
==============================================================================
--- stable/10/lib/libc/tests/Makefile   Sat Dec  3 16:02:53 2016        
(r309481)
+++ stable/10/lib/libc/tests/Makefile   Sat Dec  3 16:52:40 2016        
(r309482)
@@ -10,6 +10,7 @@ TESTS_SUBDIRS=        c063
 TESTS_SUBDIRS+=        db
 TESTS_SUBDIRS+=        gen
 TESTS_SUBDIRS+=        hash
+TESTS_SUBDIRS+=        iconv
 TESTS_SUBDIRS+=        inet
 TESTS_SUBDIRS+=        net
 TESTS_SUBDIRS+=        nss
_______________________________________________
svn-src-stable-10@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-10
To unsubscribe, send any mail to "svn-src-stable-10-unsubscr...@freebsd.org"

Reply via email to