Loading ...
Sorry, an error occurred while loading the content.

Patch 6.1.315 (extra)

Expand Messages
  • Bram Moolenaar
    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
    Message 1 of 6 , Feb 1, 2003
    • 0 Attachment
      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@... -- 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 ///
    • Walter Briscoe
      In message of Sat, 1 Feb 2003 18:49:24 in , Bram Moolenaar writes ... My original question on
      Message 2 of 6 , Feb 2, 2003
      • 0 Attachment
        In message <200302011749.h11HnOd15306@...> of Sat, 1 Feb 2003
        18:49:24 in , Bram Moolenaar <Bram@...> writes
        >
        >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
        My original question on this was about the injection of "PC " on success
        in the os_win32.c version of hostname().
        Can I suggest the following on top of Patch 6.1.315 (extra)?

        *** src/0os_win32.c Sun Feb 2 07:35:32 2003
        --- src/os_win32.c Sun Feb 2 07:48:02 2003
        ***************
        *** 2228,2237 ****
        DWORD cch = sizeof szHostName;

        if (GetComputerName(szHostName, &cch))
        ! {
        ! STRCPY(s, "PC ");
        ! STRNCPY(s + 3, szHostName, len - 3);
        ! }
        else
        STRNCPY(s, "PC (Win32 Vim)", len);
        s[len - 1] = NUL; /* make sure it's terminated */
        --- 2228,2234 ----
        DWORD cch = sizeof szHostName;

        if (GetComputerName(szHostName, &cch))
        ! STRNCPY(s, szHostName, len);
        else
        STRNCPY(s, "PC (Win32 Vim)", len);
        s[len - 1] = NUL; /* make sure it's terminated */

        --
        Walter Briscoe
      • Bram Moolenaar
        ... Sorry, I forgot to include this. I ll do that now. ... Looking at this, I wonder if we should do anything with cch , the length that GetComputerName()
        Message 3 of 6 , Feb 2, 2003
        • 0 Attachment
          Walter Briscoe wrote:

          > In message <200302011749.h11HnOd15306@...> of Sat, 1 Feb 2003
          > 18:49:24 in , Bram Moolenaar <Bram@...> writes
          > >
          > >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
          > My original question on this was about the injection of "PC " on success
          > in the os_win32.c version of hostname().
          > Can I suggest the following on top of Patch 6.1.315 (extra)?

          Sorry, I forgot to include this. I'll do that now.

          > *** src/0os_win32.c Sun Feb 2 07:35:32 2003
          > --- src/os_win32.c Sun Feb 2 07:48:02 2003
          > ***************
          > *** 2228,2237 ****
          > DWORD cch = sizeof szHostName;
          >
          > if (GetComputerName(szHostName, &cch))
          > ! {
          > ! STRCPY(s, "PC ");
          > ! STRNCPY(s + 3, szHostName, len - 3);
          > ! }
          > else
          > STRNCPY(s, "PC (Win32 Vim)", len);
          > s[len - 1] = NUL; /* make sure it's terminated */
          > --- 2228,2234 ----
          > DWORD cch = sizeof szHostName;
          >
          > if (GetComputerName(szHostName, &cch))
          > ! STRNCPY(s, szHostName, len);
          > else
          > STRNCPY(s, "PC (Win32 Vim)", len);
          > s[len - 1] = NUL; /* make sure it's terminated */

          Looking at this, I wonder if we should do anything with "cch", the
          length that GetComputerName() returns. If not, can't we directly get
          the host name into "s"?

          --
          hundred-and-one symptoms of being an internet addict:
          93. New mail alarm on your palmtop annoys other churchgoers.

          /// Bram Moolenaar -- Bram@... -- 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 ///
        • Walter Briscoe
          In message of Sun, 2 Feb 2003 20:03:17 in , Bram Moolenaar writes ... We sure can! In W2K SP3, I
          Message 4 of 6 , Feb 3, 2003
          • 0 Attachment
            In message <200302021903.h12J3Hs01735@...> of Sun, 2 Feb 2003
            20:03:17 in , Bram Moolenaar <Bram@...> writes
            >
            >Walter Briscoe wrote:
            >
            >> In message <200302011749.h11HnOd15306@...> of Sat, 1 Feb 2003
            >> 18:49:24 in , Bram Moolenaar <Bram@...> writes
            >> >
            >> >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
            >> My original question on this was about the injection of "PC " on success
            >> in the os_win32.c version of hostname().
            >> Can I suggest the following on top of Patch 6.1.315 (extra)?
            >
            >Sorry, I forgot to include this. I'll do that now.
            >
            >> *** src/0os_win32.c Sun Feb 2 07:35:32 2003
            >> --- src/os_win32.c Sun Feb 2 07:48:02 2003
            >> ***************
            >> *** 2228,2237 ****
            >> DWORD cch = sizeof szHostName;
            >>
            >> if (GetComputerName(szHostName, &cch))
            >> ! {
            >> ! STRCPY(s, "PC ");
            >> ! STRNCPY(s + 3, szHostName, len - 3);
            >> ! }
            >> else
            >> STRNCPY(s, "PC (Win32 Vim)", len);
            >> s[len - 1] = NUL; /* make sure it's terminated */
            >> --- 2228,2234 ----
            >> DWORD cch = sizeof szHostName;
            >>
            >> if (GetComputerName(szHostName, &cch))
            >> ! STRNCPY(s, szHostName, len);
            >> else
            >> STRNCPY(s, "PC (Win32 Vim)", len);
            >> s[len - 1] = NUL; /* make sure it's terminated */
            >
            >Looking at this, I wonder if we should do anything with "cch", the
            >length that GetComputerName() returns. If not, can't we directly get
            >the host name into "s"?
            >
            We sure can!
            In W2K SP3, I abstracted the code into a one compilation unit program to
            develop the following.
            The truncated result behaviour of the two versions differ.
            GetComputerName() fails if the input buffer is not long enough. My
            computer name is "D3CY200J". mch_get_host_name(x,3) sets x to "D3" with
            the old code and "PC" with the new.
            As the only call of mch_get_host_name() passes a 256 byte buffer, this
            change of behaviour never happens in practice.
            I ported the code back to os_win32.c and confirmed hostname() continues
            to work.

            *** src\0os_win32.c Sun Feb 2 07:35:32 2003
            --- src\os_win32.c. Mon Feb 3 07:56:04 2003
            ***************
            *** 2224,2240 ****
            char_u *s,
            int len)
            {
            ! char szHostName[MAX_COMPUTERNAME_LENGTH + 1];
            ! DWORD cch = sizeof szHostName;
            !
            ! if (GetComputerName(szHostName, &cch))
            {
            - STRCPY(s, "PC ");
            - STRNCPY(s + 3, szHostName, len - 3);
            - }
            - else
            STRNCPY(s, "PC (Win32 Vim)", len);
            ! s[len - 1] = NUL; /* make sure it's terminated */
            }


            --- 2224,2234 ----
            char_u *s,
            int len)
            {
            ! if (!GetComputerName(s, &len))
            {
            STRNCPY(s, "PC (Win32 Vim)", len);
            ! s[len - 1] = NUL; /* make sure it's terminated */
            ! }
            }



            --
            Walter Briscoe
          • Bram Moolenaar
            ... Passing len to GetComputerName() violates types. It might work if DWORD == int , but let s not risk that. It probably breaks on Win64. How about
            Message 5 of 6 , Feb 3, 2003
            • 0 Attachment
              Walter Briscoe wrote:

              > >Looking at this, I wonder if we should do anything with "cch", the
              > >length that GetComputerName() returns. If not, can't we directly get
              > >the host name into "s"?
              > >
              > We sure can!
              > In W2K SP3, I abstracted the code into a one compilation unit program to
              > develop the following.
              > The truncated result behaviour of the two versions differ.
              > GetComputerName() fails if the input buffer is not long enough. My
              > computer name is "D3CY200J". mch_get_host_name(x,3) sets x to "D3" with
              > the old code and "PC" with the new.
              > As the only call of mch_get_host_name() passes a 256 byte buffer, this
              > change of behaviour never happens in practice.
              > I ported the code back to os_win32.c and confirmed hostname() continues
              > to work.

              Passing "len" to GetComputerName() violates types. It might work if
              "DWORD" == "int", but let's not risk that. It probably breaks on Win64.

              How about this then:

              void
              mch_get_host_name(
              char_u *s,
              int len)
              {
              DWORD cch = len;

              if (!GetComputerName(s, &cch))
              {
              STRNCPY(s, "PC (Win32 Vim)", len);
              s[len - 1] = NUL; /* make sure it's terminated */
              }
              }

              --
              Contrary to popular belief, Unix is user friendly.
              It just happens to be selective about who it makes friends with.
              -- Dave Parnas

              /// Bram Moolenaar -- Bram@... -- 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 ///
            • Walter Briscoe
              In message of Mon, 3 Feb 2003 20:28:14 in , Bram Moolenaar writes ... I would be surprised if it
              Message 6 of 6 , Feb 4, 2003
              • 0 Attachment
                In message <200302031928.h13JSEG02846@...> of Mon, 3 Feb 2003
                20:28:14 in , Bram Moolenaar <Bram@...> writes
                >
                >Walter Briscoe wrote:
                >
                >> >Looking at this, I wonder if we should do anything with "cch", the
                >> >length that GetComputerName() returns. If not, can't we directly get
                >> >the host name into "s"?
                >> >
                >> We sure can!
                >> In W2K SP3, I abstracted the code into a one compilation unit program to
                >> develop the following.
                >> The truncated result behaviour of the two versions differ.
                >> GetComputerName() fails if the input buffer is not long enough. My
                >> computer name is "D3CY200J". mch_get_host_name(x,3) sets x to "D3" with
                >> the old code and "PC" with the new.
                >> As the only call of mch_get_host_name() passes a 256 byte buffer, this
                >> change of behaviour never happens in practice.
                >> I ported the code back to os_win32.c and confirmed hostname() continues
                >> to work.
                >
                >Passing "len" to GetComputerName() violates types. It might work if
                >"DWORD" == "int", but let's not risk that. It probably breaks on Win64.
                I would be surprised if it does break - given the abomination that is
                long long in C99. However, I agree that your idea is better than mine!
                If it does break, VC gives a diagnostic.
                warning C4133: 'function' : incompatible types - from 'short *' to 'long *'

                >
                >How about this then:
                >
                > void
                >mch_get_host_name(
                > char_u *s,
                > int len)
                >{
                > DWORD cch = len;
                >
                > if (!GetComputerName(s, &cch))
                > {
                > STRNCPY(s, "PC (Win32 Vim)", len);
                > s[len - 1] = NUL; /* make sure it's terminated */
                > }
                >}
                >

                I did a quick check with no problem with that code with Make_ivc.dsw.
                --
                Walter Briscoe
              Your message has been successfully submitted and would be delivered to recipients shortly.