Ticket #183: session.diff

File session.diff, 1.2 KB (added by jinmei, 10 years ago)
  • session.cc

     
    228228
    229229void
    230230SocketSession::establish(const char* socket_file) {
    231     int s;
    232231    struct sockaddr_un sun;
     232    if (strlen(socket_file) >= sizeof(sun.sun_path)) {
     233        isc_throw(SessionError, "Unable to connect to message queue; "
     234                  "socket file path too long: " << socket_file);
     235    }
     236    sun.sun_family = AF_UNIX;
     237    strncpy(sun.sun_path, socket_file, sizeof(sun.sun_path) - 1);
    233238
    234     s = socket(AF_UNIX, SOCK_STREAM, IPPROTO_TCP);
     239    int s = socket(AF_UNIX, SOCK_STREAM, IPPROTO_TCP);
    235240    if (s < 0) {
    236241        isc_throw(SessionError, "socket() failed");
    237242    }
     
    243248        socket_file = BIND10_MSGQ_SOCKET_FILE;
    244249    }
    245250
    246     if (strlen(socket_file) >= sizeof(sun.sun_path)) {
    247         isc_throw(SessionError, "Unable to connect to message queue; socket file path too long");
    248     }
    249 
    250     sun.sun_family = AF_UNIX;
    251     strncpy(sun.sun_path, socket_file, sizeof(sun.sun_path) - 1);
    252 
    253251    if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
    254252        close(s);
    255253        isc_throw(SessionError, "Unable to connect to message queue");