Changeset 755


Ignore:
Timestamp:
Jun 22, 2010, 1:13:59 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

network/os2: QLocalServer/QLocalSocket: Make sure the socket path name always starts with "\socket\" (fixes #166) [based on patch by rudi].

Location:
trunk/src/network/socket
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/network/socket/qlocalserver.cpp

    r651 r755  
    201201    Usually you would just pass in a name like "foo", but on Unix this
    202202    could also be a path such as "/tmp/foo" and on Windows this could
    203     be a pipe path such as "\\\\.\\pipe\\foo"
     203    be a pipe path such as "\\\\.\\pipe\\foo". On OS/2, "\\socket\\" is
     204    automatically prepended to the name if it does not already sttart with
     205    this prefix.
    204206
    205207    Note:
     
    298300    instance has not been cleaned up.
    299301
    300     On Windows, this function does nothing; on Unix, it removes the socket file
    301     given by \a name.
     302    On Windowse
     303    given by \a name.
    302304
    303305    \warning Be careful to avoid removing sockets of running instances.
  • trunk/src/network/socket/qlocalserver_os2.cpp

    r754 r755  
    6464bool QLocalServerPrivate::removeServer(const QString &name)
    6565{
    66     QString fileName;
    67     if (name.startsWith(QLatin1Char('/'))) {
    68         fileName = name;
    69     } else {
    70         fileName = QDir::cleanPath(QDir::tempPath());
    71         fileName += QLatin1Char('/') + name;
    72     }
    73     if (QFile::exists(fileName))
    74         return QFile::remove(fileName);
    75     else
    76         return true;
     66    Q_UNUSED(name);
     67    return true;
    7768}
    7869
     
    8172    Q_Q(QLocalServer);
    8273
     74
     75
     76
    8377    // determine the full server path
    84     if (requestedServerName.startsWith(QLatin1Char('/'))) {
    85         fullServerName = requestedServerName;
    86     } else {
    87         fullServerName = QDir::cleanPath(QDir::tempPath());
    88         fullServerName += QLatin1Char('/') + requestedServerName;
     78    fullServerName = QDir::toNativeSeparators(requestedServerName);
     79    if (!fullServerName.startsWith(socketPath)) {
     80        fullServerName = socketPath + requestedServerName;
    8981    }
    9082    serverName = requestedServerName;
     
    10193    struct ::sockaddr_un addr;
    10294    addr.sun_family = PF_UNIX;
    103     if (sizeof(addr.sun_path) < (uint)fullServerName.toLatin1().size() + 1) {
    104         setError(QLatin1String("QLocalServer::listen"));
    105         closeServer();
    106         return false;
    107     }
    108     ::memcpy(addr.sun_path, fullServerName.toLatin1().data(),
    109              fullServerName.toLatin1().size() + 1);
     95    addr.sun_len = sizeof(sockaddr_un);
     96    QByteArray fsn = fullServerName.toLocal8Bit();
     97    if (sizeof(addr.sun_path) < (uint)fsn.size() + 1) {
     98        errno = E2BIG; // indicate buffer overflow
     99        setError(QLatin1String("QLocalServer::listen"));
     100        closeServer();
     101        return false;
     102    }
     103    ::strcpy(addr.sun_path, fsn);
    110104
    111105    // bind
     
    127121        closeServer();
    128122        listenSocket = -1;
    129         if (error != QAbstractSocket::AddressInUseError)
    130             QFile::remove(fullServerName);
    131123        return false;
    132124    }
     
    151143        socketNotifier = 0;
    152144    }
    153 
    154     if (!fullServerName.isEmpty())
    155         QFile::remove(fullServerName);
    156145}
    157146
  • trunk/src/network/socket/qlocalsocket.cpp

    r651 r755  
    5353    \brief The QLocalSocket class provides a local socket.
    5454
    55     On Windows this is a named pipe and on Unix this is a local domain socket.
     55    On Windows this is a named pipe, on Unix and OS/2 this is a local domain
     56    socket.
    5657
    5758    If an error occurs, socketError() returns the type of error, and
  • trunk/src/network/socket/qlocalsocket_os2.cpp

    r754 r755  
    271271    QString connectingPathName;
    272272
     273
     274
     275
    273276    // determine the full server path
    274     if (connectingName.startsWith(QLatin1Char('/'))) {
    275         connectingPathName = connectingName;
    276     } else {
    277         connectingPathName = QDir::tempPath();
    278         connectingPathName += QLatin1Char('/') + connectingName;
     277    connectingPathName = QDir::toNativeSeparators(connectingName);
     278    if (!connectingName.startsWith(socketPath)) {
     279        connectingPathName = socketPath + connectingName;
    279280    }
    280281
    281282    struct sockaddr_un name;
    282283    name.sun_family = PF_UNIX;
    283     if (sizeof(name.sun_path) < (uint)connectingPathName.toLatin1().size() + 1) {
     284    name.sun_len = sizeof(sockaddr_un);
     285    QByteArray cpn = connectingPathName.toLocal8Bit();
     286    if (sizeof(name.sun_path) < (uint)cpn.size() + 1) {
    284287        QString function = QLatin1String("QLocalSocket::connectToServer");
    285288        errorOccurred(QLocalSocket::ServerNotFoundError, function);
    286289        return;
    287290    }
    288     ::memcpy(name.sun_path, connectingPathName.toLatin1().data(),
    289              connectingPathName.toLatin1().size() + 1);
     291    ::
     292
    290293    if (-1 == ::connect(connectingSocket, (struct sockaddr *)&name, sizeof(name))) {
    291294        QString function = QLatin1String("QLocalSocket::connectToServer");
Note: See TracChangeset for help on using the changeset viewer.