mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	buf: do not expand $() in buf_expand_shell_variables()
This commit is contained in:
		
							parent
							
								
									e8ec8ea7ff
								
							
						
					
					
						commit
						c6c1f8e04b
					
				
					 1 changed files with 9 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "common/buf.h"
 | 
			
		||||
#include "common/mem.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,6 +16,12 @@ strip_curly_braces(char *s)
 | 
			
		|||
	s[len] = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool
 | 
			
		||||
isvalid(char p)
 | 
			
		||||
{
 | 
			
		||||
	return isalnum(p) || p == '_' || p == '{' || p == '}';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
buf_expand_shell_variables(struct buf *s)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -24,12 +31,12 @@ buf_expand_shell_variables(struct buf *s)
 | 
			
		|||
	buf_init(&environment_variable);
 | 
			
		||||
 | 
			
		||||
	for (int i = 0 ; i < s->len ; i++) {
 | 
			
		||||
		if (s->buf[i] == '$') {
 | 
			
		||||
		if (s->buf[i] == '$' && isvalid(s->buf[i+1])) {
 | 
			
		||||
			/* expand environment variable */
 | 
			
		||||
			environment_variable.len = 0;
 | 
			
		||||
			buf_add(&environment_variable, s->buf + i + 1);
 | 
			
		||||
			char *p = environment_variable.buf;
 | 
			
		||||
			while (isalnum(*p) || *p == '_' || *p == '{' || *p == '}') {
 | 
			
		||||
			while (isvalid(*p)) {
 | 
			
		||||
				++p;
 | 
			
		||||
			}
 | 
			
		||||
			*p = '\0';
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue