mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Marshall NULL strings without crashing
This commit is contained in:
		
							parent
							
								
									4eb536091a
								
							
						
					
					
						commit
						3bbbd15c65
					
				
					 1 changed files with 12 additions and 8 deletions
				
			
		| 
						 | 
					@ -338,7 +338,7 @@ wl_connection_vmarshal(struct wl_connection *connection,
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 's':
 | 
							case 's':
 | 
				
			||||||
			s = va_arg(ap, const char *);
 | 
								s = va_arg(ap, const char *);
 | 
				
			||||||
			length = strlen(s);
 | 
								length = s ? strlen(s) : 0;
 | 
				
			||||||
			*p++ = length;
 | 
								*p++ = length;
 | 
				
			||||||
			memcpy(p, s, length);
 | 
								memcpy(p, s, length);
 | 
				
			||||||
			p += DIV_ROUNDUP(length, sizeof(*p));
 | 
								p += DIV_ROUNDUP(length, sizeof(*p));
 | 
				
			||||||
| 
						 | 
					@ -456,6 +456,9 @@ wl_connection_demarshal(struct wl_connection *connection,
 | 
				
			||||||
				goto out;
 | 
									goto out;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if (length == 0) {
 | 
				
			||||||
 | 
									values[i].string = NULL;
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
				values[i].string = malloc(length + 1);
 | 
									values[i].string = malloc(length + 1);
 | 
				
			||||||
				if (values[i].string == NULL) {
 | 
									if (values[i].string == NULL) {
 | 
				
			||||||
					errno = ENOMEM;
 | 
										errno = ENOMEM;
 | 
				
			||||||
| 
						 | 
					@ -464,6 +467,7 @@ wl_connection_demarshal(struct wl_connection *connection,
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				memcpy(values[i].string, p, length);
 | 
									memcpy(values[i].string, p, length);
 | 
				
			||||||
				values[i].string[length] = '\0';
 | 
									values[i].string[length] = '\0';
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			p = next;
 | 
								p = next;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 'o':
 | 
							case 'o':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue