To: vim-dev@vim.org Subject: Patch 6.1.315 (extra) Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.315 (extra) Problem: A very long hostname may lead to an unterminated string. Failing to obtain a hostname may result in garbage. (Walter Briscoe) Solution: Add a NUL at the end of the hostname buffer. Files: src/os_mac.c, src/os_msdos.c, src/os_unix.c, src/os_win16.c, src/os_win32.c *** ../vim61.314/src/os_mac.c Fri May 17 19:29:08 2002 --- src/os_mac.c Fri Jan 24 23:11:01 2003 *************** *** 694,715 **** } /* ! * Insert host name is s[len]. */ - void mch_get_host_name(s, len) char_u *s; int len; { #if defined(__MRC__) || defined(__SC__) || defined(__APPLE_CC__) ! s[0] = '\0'; /* TODO: use Gestalt information */ #else struct utsname vutsname; ! uname(&vutsname); ! STRNCPY(s, vutsname.nodename, len); #endif } /* --- 694,717 ---- } /* ! * Copy host name into s[len]. */ void mch_get_host_name(s, len) char_u *s; int len; { #if defined(__MRC__) || defined(__SC__) || defined(__APPLE_CC__) ! STRNCPY(s, "Mac", len); /* TODO: use Gestalt information */ #else struct utsname vutsname; ! if (uname(&vutsname) < 0) ! *s = NUL; ! else ! STRNCPY(s, vutsname.nodename, len); #endif + s[len - 1] = NUL; /* make sure it's terminated */ } /* *** ../vim61.314/src/os_msdos.c Sun Oct 13 20:08:14 2002 --- src/os_msdos.c Tue Jan 21 19:10:44 2003 *************** *** 1518,1523 **** --- 1518,1524 ---- #else STRNCPY(s, "PC (16 bits Vim)", len); #endif + s[len - 1] = NUL; /* make sure it's terminated */ } /* *** ../vim61.314/src/os_unix.c Wed Jan 29 22:08:43 2003 --- src/os_unix.c Mon Jan 27 20:09:54 2003 *************** *** 1854,1861 **** { struct utsname vutsname; ! uname(&vutsname); ! STRNCPY(s, vutsname.nodename, len); } #else /* HAVE_SYS_UTSNAME_H */ --- 1854,1864 ---- { struct utsname vutsname; ! if (uname(&vutsname) < 0) ! *s = NUL; ! else ! STRNCPY(s, vutsname.nodename, len); ! s[len - 1] = NUL; /* make sure it's terminated */ } #else /* HAVE_SYS_UTSNAME_H */ *************** *** 1873,1878 **** --- 1876,1882 ---- # else gethostname((char *)s, len); # endif + s[len - 1] = NUL; /* make sure it's terminated */ } #endif /* HAVE_SYS_UTSNAME_H */ *** ../vim61.314/src/os_win16.c Wed May 15 22:00:04 2002 --- src/os_win16.c Tue Jan 21 19:10:08 2003 *************** *** 320,325 **** --- 320,326 ---- int len) { STRNCPY(s, "PC (16 bits Vim)", len); + s[len - 1] = NUL; /* make sure it's terminated */ } *** ../vim61.314/src/os_win32.c Mon Sep 30 21:30:08 2002 --- src/os_win32.c Tue Jan 21 19:09:50 2003 *************** *** 2234,2239 **** --- 2234,2240 ---- } else STRNCPY(s, "PC (Win32 Vim)", len); + s[len - 1] = NUL; /* make sure it's terminated */ } *** ../vim61.314/src/version.c Sat Feb 1 17:13:28 2003 --- src/version.c Sat Feb 1 18:45:21 2003 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 315, /**/ -- From "know your smileys": :-E Has major dental problems /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///