Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8043720

(smartcardio) Native memory should be handled more accurately

XMLWordPrintable

        There are a few issues with the native memory allocation in share/native/sun/security/smartcardio/pcsc.c:

        1)
            readerState = calloc(readers, sizeof(SCARD_READERSTATE));
            if (readerState == NULL) {
                throwOutOfMemoryError(env, NULL);

        calloc() can return NULL due to readers be zero.
        In this case OOM would be confusing.

        2)
            for (i = 0; i < readers; i++) {
                free((char *)readerState[i].szReader);
            }

        We can get here upon an error, so readerState[i].szReader may not be initialized.

        3)
            mszReaders = malloc(size);
            if (mszReaders == NULL) {
                throwOutOfMemoryError(env, NULL);
                return NULL;
            }

        If size happens to be zero, we'll get a confusing OOM.

        4)
            tab = (char **)malloc(cnt * sizeof(char *));
            if (tab == NULL) {
                throwOutOfMemoryError(env, NULL);
                return NULL;
            }

        Again, we can get NULL from malloc, if cnt == 0.

              igerasim Ivan Gerasimov
              igerasim Ivan Gerasimov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: