mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Break version check into a separate function, and limit version to 8 bits.
This commit is contained in:
		
							
								
								
									
										31
									
								
								proc.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								proc.c
									
									
									
									
									
								
							@@ -49,7 +49,8 @@ struct tmuxpeer {
 | 
				
			|||||||
	void		*arg;
 | 
						void		*arg;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void proc_update_event(struct tmuxpeer *);
 | 
					static int	peer_check_version(struct tmuxpeer *, struct imsg *);
 | 
				
			||||||
 | 
					static void	proc_update_event(struct tmuxpeer *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
proc_event_cb(unused int fd, short events, void *arg)
 | 
					proc_event_cb(unused int fd, short events, void *arg)
 | 
				
			||||||
@@ -57,7 +58,6 @@ proc_event_cb(unused int fd, short events, void *arg)
 | 
				
			|||||||
	struct tmuxpeer	*peer = arg;
 | 
						struct tmuxpeer	*peer = arg;
 | 
				
			||||||
	ssize_t		 n;
 | 
						ssize_t		 n;
 | 
				
			||||||
	struct imsg	 imsg;
 | 
						struct imsg	 imsg;
 | 
				
			||||||
	int		 v;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!(peer->flags & PEER_BAD) && (events & EV_READ)) {
 | 
						if (!(peer->flags & PEER_BAD) && (events & EV_READ)) {
 | 
				
			||||||
		if ((n = imsg_read(&peer->ibuf)) == -1 || n == 0) {
 | 
							if ((n = imsg_read(&peer->ibuf)) == -1 || n == 0) {
 | 
				
			||||||
@@ -73,14 +73,7 @@ proc_event_cb(unused int fd, short events, void *arg)
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
			log_debug("peer %p message %d", peer, imsg.hdr.type);
 | 
								log_debug("peer %p message %d", peer, imsg.hdr.type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			v = imsg.hdr.peerid;
 | 
								if (peer_check_version(peer, &imsg) != 0) {
 | 
				
			||||||
			if (imsg.hdr.type != MSG_VERSION &&
 | 
					 | 
				
			||||||
			    v != PROTOCOL_VERSION) {
 | 
					 | 
				
			||||||
				log_debug("peer %p bad version %d", peer, v);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				proc_send(peer, MSG_VERSION, -1, NULL, 0);
 | 
					 | 
				
			||||||
				peer->flags |= PEER_BAD;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (imsg.fd != -1)
 | 
									if (imsg.fd != -1)
 | 
				
			||||||
					close(imsg.fd);
 | 
										close(imsg.fd);
 | 
				
			||||||
				imsg_free(&imsg);
 | 
									imsg_free(&imsg);
 | 
				
			||||||
@@ -115,6 +108,24 @@ proc_signal_cb(int signo, unused short events, void *arg)
 | 
				
			|||||||
	tp->signalcb(signo);
 | 
						tp->signalcb(signo);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int
 | 
				
			||||||
 | 
					peer_check_version(struct tmuxpeer *peer, struct imsg *imsg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int	version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						version = imsg->hdr.peerid & 0xff;
 | 
				
			||||||
 | 
						if (imsg->hdr.type != MSG_VERSION && version != PROTOCOL_VERSION) {
 | 
				
			||||||
 | 
							log_debug("peer %p bad version %d", peer, version);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							proc_send(peer, MSG_VERSION, -1, NULL, 0);
 | 
				
			||||||
 | 
							peer->flags |= PEER_BAD;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						imsg->hdr.peerid >>= 8;
 | 
				
			||||||
 | 
						return (0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
proc_update_event(struct tmuxpeer *peer)
 | 
					proc_update_event(struct tmuxpeer *peer)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user