mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	protocol-native: hex encode invalid SEC_LABEL
When the sec label contains invalid chars, hexencode it to avoid causing problems with invalid strings later.
This commit is contained in:
		
							parent
							
								
									9499e4969b
								
							
						
					
					
						commit
						de12a24e77
					
				
					 1 changed files with 29 additions and 4 deletions
				
			
		| 
						 | 
					@ -33,6 +33,7 @@
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <fcntl.h>
 | 
					#include <fcntl.h>
 | 
				
			||||||
#include <sys/file.h>
 | 
					#include <sys/file.h>
 | 
				
			||||||
 | 
					#include <ctype.h>
 | 
				
			||||||
#if HAVE_PWD_H
 | 
					#if HAVE_PWD_H
 | 
				
			||||||
#include <pwd.h>
 | 
					#include <pwd.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -390,6 +391,17 @@ static const struct pw_protocol_native_connection_events server_conn_events = {
 | 
				
			||||||
	.need_flush = on_server_need_flush,
 | 
						.need_flush = on_server_need_flush,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool check_print(const char *buffer, int len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						while (len > 1 && buffer[len-1] == 0)
 | 
				
			||||||
 | 
							len--;
 | 
				
			||||||
 | 
						for (i = 0; i < len; i++)
 | 
				
			||||||
 | 
							if (!isprint(buffer[i]))
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct client_data *client_new(struct server *s, int fd)
 | 
					static struct client_data *client_new(struct server *s, int fd)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct client_data *this;
 | 
						struct client_data *this;
 | 
				
			||||||
| 
						 | 
					@ -404,7 +416,7 @@ static struct client_data *client_new(struct server *s, int fd)
 | 
				
			||||||
	struct pw_properties *props;
 | 
						struct pw_properties *props;
 | 
				
			||||||
	char buffer[1024];
 | 
						char buffer[1024];
 | 
				
			||||||
	struct protocol_data *d = pw_protocol_get_user_data(protocol);
 | 
						struct protocol_data *d = pw_protocol_get_user_data(protocol);
 | 
				
			||||||
	int res;
 | 
						int i, res;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	props = pw_properties_new(PW_KEY_PROTOCOL, "protocol-native", NULL);
 | 
						props = pw_properties_new(PW_KEY_PROTOCOL, "protocol-native", NULL);
 | 
				
			||||||
	if (props == NULL)
 | 
						if (props == NULL)
 | 
				
			||||||
| 
						 | 
					@ -426,11 +438,24 @@ static struct client_data *client_new(struct server *s, int fd)
 | 
				
			||||||
			pw_log_info("server %p: security label not available", s);
 | 
								pw_log_info("server %p: security label not available", s);
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			pw_log_warn("server %p: security label error: %m", s);
 | 
								pw_log_warn("server %p: security label error: %m", s);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if (!check_print(buffer, len)) {
 | 
				
			||||||
 | 
								char *hex, *p;
 | 
				
			||||||
 | 
								static const char *ch = "0123456789abcdef";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								p = hex = alloca(len * 2 + 10);
 | 
				
			||||||
 | 
								p += snprintf(p, 5, "hex:");
 | 
				
			||||||
 | 
								for(i = 0; i < (int)len; i++)
 | 
				
			||||||
 | 
									p += snprintf(p, 3, "%c%c",
 | 
				
			||||||
 | 
											ch[buffer[i] >> 4], ch[buffer[i] & 0xf]);
 | 
				
			||||||
 | 
								pw_properties_set(props, PW_KEY_SEC_LABEL, hex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			/* buffer is not null terminated, must use length explicitly */
 | 
								/* buffer is not null terminated, must use length explicitly */
 | 
				
			||||||
			pw_properties_setf(props, PW_KEY_SEC_LABEL, "%.*s",
 | 
								pw_properties_setf(props, PW_KEY_SEC_LABEL, "%.*s",
 | 
				
			||||||
					(int)len, buffer);
 | 
										(int)len, buffer);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
#elif defined(__FreeBSD__)
 | 
					#elif defined(__FreeBSD__)
 | 
				
			||||||
	len = sizeof(xucred);
 | 
						len = sizeof(xucred);
 | 
				
			||||||
	if (getsockopt(fd, 0, LOCAL_PEERCRED, &xucred, &len) < 0) {
 | 
						if (getsockopt(fd, 0, LOCAL_PEERCRED, &xucred, &len) < 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue