mirror of
				https://github.com/alsa-project/alsa-lib.git
				synced 2025-11-03 09:01:52 -05:00 
			
		
		
		
	config: parse_string() fix the dynamic buffer allocation failure code (coverity)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
		
							parent
							
								
									4aa960c48b
								
							
						
					
					
						commit
						990b1a53ed
					
				
					 1 changed files with 12 additions and 4 deletions
				
			
		
							
								
								
									
										16
									
								
								src/conf.c
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								src/conf.c
									
										
									
									
									
								
							| 
						 | 
					@ -4747,8 +4747,11 @@ static int parse_string(const char **ptr, char **val)
 | 
				
			||||||
			return -EINVAL;
 | 
								return -EINVAL;
 | 
				
			||||||
		case '\\':
 | 
							case '\\':
 | 
				
			||||||
			c = parse_char(ptr);
 | 
								c = parse_char(ptr);
 | 
				
			||||||
			if (c < 0)
 | 
								if (c < 0) {
 | 
				
			||||||
 | 
									if (alloc > bufsize)
 | 
				
			||||||
 | 
										free(buf);
 | 
				
			||||||
				return c;
 | 
									return c;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			(*ptr)++;
 | 
								(*ptr)++;
 | 
				
			||||||
| 
						 | 
					@ -4768,12 +4771,17 @@ static int parse_string(const char **ptr, char **val)
 | 
				
			||||||
			alloc *= 2;
 | 
								alloc *= 2;
 | 
				
			||||||
			if (old_alloc == bufsize) {
 | 
								if (old_alloc == bufsize) {
 | 
				
			||||||
				buf = malloc(alloc);
 | 
									buf = malloc(alloc);
 | 
				
			||||||
 | 
									if (!buf)
 | 
				
			||||||
 | 
										return -ENOMEM;
 | 
				
			||||||
				memcpy(buf, _buf, old_alloc);
 | 
									memcpy(buf, _buf, old_alloc);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				buf = realloc(buf, alloc);
 | 
									char *buf2 = realloc(buf, alloc);
 | 
				
			||||||
 | 
									if (!buf2) {
 | 
				
			||||||
 | 
										free(buf);
 | 
				
			||||||
 | 
										return -ENOMEM;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									buf = buf2;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if (!buf)
 | 
					 | 
				
			||||||
				return -ENOMEM;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		buf[idx++] = c;
 | 
							buf[idx++] = c;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue