@@ -732,6 +732,7 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename)
732732/* the simplest way to transfer the data is to convert them into */
733733/* plain text and interpret them on the other side. */
734734{
735+ assert (conn != NULL );
735736 Stat cfst ;
736737 struct stat statbuf , statlinkbuf ;
737738 char linkbuf [CF_BUFSIZE ], filename [CF_BUFSIZE - 128 ];
@@ -874,10 +875,17 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename)
874875
875876 memset (sendbuffer , 0 , CF_MSGSIZE );
876877
878+ // +3 because we need to prepend 'OK:' to the path
879+ if (strlen (linkbuf )+ 3 > CF_MSGSIZE ) {
880+ NDEBUG_UNUSED int ret = snprintf (sendbuffer , CF_MSGSIZE , "BAD: Symlink resolves to a path too long (%ld) to send over the protocol." , strlen (linkbuf )+ 3 );
881+ assert (ret > 0 && ret < CF_MSGSIZE );
882+ SendTransaction (conn -> conn_info , sendbuffer , 0 , CF_DONE );
883+ return -1 ;
884+ }
877885 if (cfst .cf_readlink != NULL )
878886 {
879- strcpy (sendbuffer , "OK:" );
880- strcat ( sendbuffer , cfst . cf_readlink );
887+ NDEBUG_UNUSED int ret = snprintf (sendbuffer , CF_MSGSIZE , "OK:%s" , linkbuf );
888+ assert ( ret > 0 && ret < CF_MSGSIZE );
881889 }
882890 else
883891 {
0 commit comments