Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87812

Documentation missing on QSharedMemory for inter-user communication

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3: Somewhat important
    • None
    • 5.15.0 RC2
    • Core: I/O
    • None
    • Linux/X11

    Description

      QSharedMemory can't be shared between proccess owned by different users. Probably it was done by secure reasons. But it's not expected behaviour and it is not documented.

       

      In my personol case I run my app first in one user then killall -9 my_app then run it with another user and get weird error about QSharedMemory. Then I looked at QSharedMemory documentation and found nothing. Then I opened QSharedMemory sources and found

      QString
      QSharedMemoryPrivate::makePlatformSafeKey(const QString &key,
                                                const QString &prefix)
      {
          if (key.isEmpty())
              return QString();
      
          QString result = prefix;
      
          for (QChar ch : key) {
              if ((ch >= QLatin1Char('a') && ch <= QLatin1Char('z')) ||
                 (ch >= QLatin1Char('A') && ch <= QLatin1Char('Z')))
                 result += ch;
          }
      
          QByteArray hex = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha1).toHex();
          result.append(QLatin1String(hex));
      #ifdef Q_OS_WIN
          return result;
      #elif defined(QT_POSIX_IPC)
          return QLatin1Char('/') + result;
      #else
          return QDir::tempPath() + QLatin1Char('/') + result;
      #endif
      }
      

      and

       

      
      int QSharedMemoryPrivate::createUnixKeyFile(const QString &fileName)
      {
          int fd = qt_safe_open(QFile::encodeName(fileName).constData(),
                  O_EXCL | O_CREAT | O_RDWR, 0640);
          ...
      }
      
      

      So please update documentation. Add some note that QSharedMemory can't be used for inter-user communication and that filename of key must be different for different users.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              taurus Ivan Romanov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes