Andersbakken / rtags

A client/server indexer for c/c++/objc[++] with integration for Emacs based on clang.
http://www.rtags.net
GNU General Public License v3.0
1.83k stars 252 forks source link

Long --socket-file=NAME failure without appropriate message #1042

Open JohnC32 opened 7 years ago

JohnC32 commented 7 years ago

Please mark appropriate

Problem description

If you run "rdm --socket-file=/long/path/to/rdm_socket_file ... " the server will most likely start and use an incorrect (truncated socket file). I believe the fix is to update SocketClient.cpp and SocketServer.cpp to have something like

 if (path.length >=sizeof(addr_un.sun_path)) {error("socket file path too long, must be less than %d",sizeof(addr_un.sun_path);} before:
 strncpy(addr_un.sun_path, path.constData(), sizeof(addr_un.sun_path));
 and change strncpy to a strcpy as it will be safe.

(I haven't looked through your code enough to see how to report such an error). See man 7 unix for details on the socket file limit.

I believe the sizeof(addr_un.sum_path) results in 108 on Linux and 104 on Mac and is not adjustable. See https://serverfault.com/questions/641347/check-if-a-path-exceeds-maximum-for-unix-domain-socket https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars https://stackoverflow.com/questions/34829600/why-is-the-maximal-path-length-allowed-for-unix-sockets-on-linux-108

Expected behavior

Specifying a socket file that is incorrect (too long) should result in an error.

Actual behavior

rdm may or may not start. It depends upon where the long socket file was truncated. If it does start, it will start incorrectly and use a different named socket file from what was specified.

Environment

Debian 8

4.0.1

Feature request

Describe the feature we should add to RTags.

JohnC32 commented 7 years ago

Also, a side note, when compiling RTags with clang 4.0.1, I see a lot of warnings of the form:

/path/to/rtags/src/rct/rct/String.h:38:5: warning: declaration of ‘end’ shadows a member of 'this' [-Wshadow]