Skip to content

Missing Sanity Check for malloc() in PC/_msi.c #68043

Closed

Description

@dogbert2
mannequin
BPO 23855
Nosy @tjguk, @berkerpeksag, @zware, @zooba, @ZackerySpytz, @miss-islington
PRs
  • bpo-23855: Add missing NULL checks for malloc() in _msi.c #9038
  • [3.7] bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038) #9110
  • [3.6] bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038) #9115
  • [2.7] bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038) #9116
  • Files
  • _msi.c.patch: Patch File (diff -u) for this bug
  • _msi.c.patch: Updated patch file for first bug report
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2018-09-08.01:59:29.435>
    created_at = <Date 2015-04-02.22:11:43.674>
    labels = ['3.8', 'type-bug', '3.7', 'OS-windows']
    title = 'Missing Sanity Check for malloc() in PC/_msi.c'
    updated_at = <Date 2018-09-11.06:52:17.237>
    user = 'https://bugs.python.org/dogbert2'

    bugs.python.org fields:

    activity = <Date 2018-09-11.06:52:17.237>
    actor = 'ZackerySpytz'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-09-08.01:59:29.435>
    closer = 'berker.peksag'
    components = ['Windows']
    creation = <Date 2015-04-02.22:11:43.674>
    creator = 'dogbert2'
    dependencies = []
    files = ['38811', '38847']
    hgrepos = []
    issue_num = 23855
    keywords = ['patch']
    message_count = 7.0
    messages = ['239948', '240159', '324492', '324803', '324808', '324934', '324935']
    nosy_count = 7.0
    nosy_names = ['tim.golden', 'berker.peksag', 'zach.ware', 'steve.dower', 'dogbert2', 'ZackerySpytz', 'miss-islington']
    pr_nums = ['9038', '9110', '9115', '9116']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23855'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. dogbert2 commented on Apr 2, 2015

      dogbert2mannequin
      MannequinAuthor

      Hello All,

      In reviewing code in Python-3.4.3/PC/_msi.c, I found a call to malloc() at line 326 in function 'static PyObject* msierror(int status)' in which the call is made and assigned to variable 'res', but no check for NULL, indicating failure is made afterwards. The patch below corrects this issue:

      --- _msi.c.orig 2015-04-02 15:01:02.882326352 -0700
      +++ _msi.c      2015-04-02 15:02:43.382099357 -0700
      @@ -324,6 +324,10 @@
           code = MsiRecordGetInteger(err, 1); /* XXX code */
           if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) {
               res = malloc(size+1);
      +       if (res == NULL) /* malloc() failed, out of memory... */
      +           PyErr_SetString(MSIError, "out of memory");
      +           return NULL;
      +       }
               MsiFormatRecord(0, err, res, &size);
               res[size]='\0';
           }
    2. added
      type-bug
      on Apr 2, 2015
    3. dogbert2 commented on Apr 6, 2015

      dogbert2mannequin
      MannequinAuthor

      In directory 'PC', file '_msi.c', I found another call to
      malloc() which was not checked for a return value of NULL
      which would indicate failure. The new patch file is below:

      --- _msi.c.orig 2015-04-02 15:01:02.882326352 -0700
      +++ _msi.c      2015-04-04 16:36:56.919605881 -0700
      @@ -324,6 +324,10 @@
           code = MsiRecordGetInteger(err, 1); /* XXX code */
           if (MsiFormatRecord(0, err, res, &size) == ERROR_MORE_DATA) {
               res = malloc(size+1);
      +       if (res == NULL) /* malloc() failed, out of memory... */
      +           PyErr_SetString(MSIError, "out of memory");
      +           return NULL;
      +       }
               MsiFormatRecord(0, err, res, &size);
               res[size]='\0';
           }
      @@ -547,6 +551,10 @@
               &fval, sval, &ssize);
           if (status == ERROR_MORE_DATA) {
               sval = malloc(ssize);
      +       if (sval == NULL) { /* malloc() failed, out of memory... */
      +           PyErr_SetString(MSIError, "out of memory");
      +           return NULL;
      +       }
               status = MsiSummaryInfoGetProperty(si->h, field, &type, &ival,
                   &fval, sval, &ssize);
           }
    4. ZackerySpytz commented on Sep 3, 2018

      ZackerySpytzmannequin
      Mannequin

      The suggested patch is not acceptable: MemoryError should be raised in the unlikely event of a malloc() failure, there's a missing call to MsiCloseHandle(), the use of tabs violates PEP-7, and there's a blatant syntax error.

    5. added
      3.7 (EOL)
      3.8 (EOL)
      on Sep 3, 2018
    6. berkerpeksag commented on Sep 7, 2018

      @berkerpeksag
      Member

      New changeset 4e51937 by Berker Peksag (Zackery Spytz) in branch 'master':
      bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038)
      4e51937

    7. miss-islington commented on Sep 7, 2018

      @miss-islington
      Contributor

      New changeset 7399407 by Miss Islington (bot) in branch '3.7':
      bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038)
      7399407

    8. miss-islington commented on Sep 10, 2018

      @miss-islington
      Contributor

      New changeset f51a466 by Miss Islington (bot) in branch '2.7':
      bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038)
      f51a466

    9. miss-islington commented on Sep 10, 2018

      @miss-islington
      Contributor

      New changeset 8a0c254 by Miss Islington (bot) in branch '3.6':
      bpo-23855: Add missing NULL checks for malloc() in _msi.c (GH-9038)
      8a0c254

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)3.8 (EOL)OS-windowstype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions