LibVNC / libvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.
GNU General Public License v2.0
1.22k stars 514 forks source link

Memory leaks in src/libvncserver/rfbserver.c, src/libvncserver/sockets.c, src/libvncserver/rfbserver.c #660

Open shaue188 opened 2 weeks ago

shaue188 commented 2 weeks ago

Additional context

Our company uses libvncserver in our product. I am working on static analysis, and one of my tasks was to scan libvncserver package. During the scan, I found some errors in code:

Describe errors

  1. https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/rfbserver.c#L1409 Handle dirp is created by calling function 'opendir' and lost at https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/rfbserver.c#L1415, need closedir(dirp) there.

  2. https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/sockets.c#L1211 Handle 'sock' is created by calling function 'socket' and lost at https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/sockets.c#L1216 and https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/sockets.c#L1219, need close(sock) there.

  3. https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/rfbserver.c#L347 Dynamic memory, referenced by 'cl->host', is allocated by calling function 'strdup' and lost at https://github.com/LibVNC/libvncserver/blob/master/src/libvncserver/rfbserver.c#L364, possibly need rfbCloseClient(cl) there

bk138 commented 2 weeks ago

Thanks for spotting - happy about one or three PRs!