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

[PATCH] Disallow NUL bytes in all strings, not only dictionary keys

Expand Messages
  • ZyX
    This patch is to be applied on top of patch that disallows NUL bytes in dictionary keys. # HG changeset patch # User ZyX # Date 1346592005
    Message 1 of 3 , Sep 2, 2012
    • 0 Attachment
      This patch is to be applied on top of patch that disallows NUL bytes in dictionary keys.

      # HG changeset patch
      # User ZyX <kp-pav@...>
      # Date 1346592005 -14400
      # Node ID d998aa5da5a200f26fd3fb5cdc5b2ba503d22e46
      # Parent 7d27a9afedaa06240a7fb2774000e26fe50cc324
      Don’t allow NUL bytes in strings

      diff -r 7d27a9afedaa -r d998aa5da5a2 src/if_py_both.h
      --- a/src/if_py_both.h Sat Sep 01 22:07:22 2012 +0400
      +++ b/src/if_py_both.h Sun Sep 02 17:19:40 2012 +0400
      @@ -2535,8 +2535,10 @@
      #if PY_MAJOR_VERSION >= 3
      else if (PyBytes_Check(obj))
      {
      - char_u *result = (char_u *) PyBytes_AsString(obj);
      -
      + char_u *result;
      +
      + if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
      + return -1;
      if (result == NULL)
      return -1;

      @@ -2554,7 +2556,8 @@
      if (bytes == NULL)
      return -1;

      - result = (char_u *) PyBytes_AsString(bytes);
      + if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
      + return -1;
      if (result == NULL)
      return -1;

      @@ -2577,7 +2580,8 @@
      if (bytes == NULL)
      return -1;

      - result=(char_u *) PyString_AsString(bytes);
      + if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
      + return -1;
      if (result == NULL)
      return -1;

      @@ -2592,8 +2596,10 @@
      }
      else if (PyString_Check(obj))
      {
      - char_u *result = (char_u *) PyString_AsString(obj);
      -
      + char_u *result;
      +
      + if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
      + return -1;
      if (result == NULL)
      return -1;

      diff -r 7d27a9afedaa -r d998aa5da5a2 src/if_python3.c
      --- a/src/if_python3.c Sat Sep 01 22:07:22 2012 +0400
      +++ b/src/if_python3.c Sun Sep 02 17:19:40 2012 +0400
      @@ -85,6 +85,7 @@
      #define PyString_AsString(obj) PyBytes_AsString(obj)
      #define PyString_Size(obj) PyBytes_GET_SIZE(bytes)
      #define PyString_FromString(repr) PyUnicode_FromString(repr)
      +#define PyString_AsStringAndSize(obj, buffer, len) PyBytes_AsStringAndSize(obj, buffer, len)

      #if defined(DYNAMIC_PYTHON3) || defined(PROTO)

      @@ -552,7 +553,7 @@
      #define DICTKEY_GET(err) \
      if (PyBytes_Check(keyObject)) \
      { \
      - if (PyBytes_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
      + if (PyString_AsStringAndSize(keyObject, (char **) &key, NULL) == -1) \
      return err; \
      } \
      else if (PyUnicode_Check(keyObject)) \
      @@ -560,7 +561,7 @@
      bytes = PyString_AsBytes(keyObject); \
      if (bytes == NULL) \
      return err; \
      - if (PyBytes_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
      + if (PyString_AsStringAndSize(bytes, (char **) &key, NULL) == -1) \
      return err; \
      } \
      else \

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Tony Mechelynck
      ... Should null bytes be disallowed by some special code, or are they _already_ disallowed by virtue of what is described under ... and, for old-style Mac, ...
      Message 2 of 3 , Sep 2, 2012
      • 0 Attachment
        On 02/09/12 16:13, ZyX wrote:
        > This patch is to be applied on top of patch that disallows NUL bytes in dictionary keys.

        Should null bytes be disallowed by some special code, or are they
        _already_ disallowed by virtue of what is described under
        :help NL-used-for-Nul
        and, for old-style Mac,
        :help CR-used-for-NL
        ?


        Best regards,
        Tony.
        --
        If mathematically you end up with the wrong answer, try multiplying by
        the page number.


        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • ZyX
        ... NUL byte in old C-style strings end them. Vim uses old C-style strings. Before the patch things like “{ abc 0def :1}” were truncated to
        Message 3 of 3 , Sep 2, 2012
        • 0 Attachment
          > Should null bytes be disallowed by some special code, or are they
          > _already_ disallowed by virtue of what is described under
          >
          > :help NL-used-for-Nul
          >
          > and, for old-style Mac,
          >
          > :help CR-used-for-NL
          >
          > ?
          NUL byte in old C-style strings end them. Vim uses old C-style strings.

          Before the patch things like “{'abc\0def':1}” were truncated to “{'abc':1}”. Now they are an error: I don’t like code that silently makes the data wrong.

          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        Your message has been successfully submitted and would be delivered to recipients shortly.