Skip to contentSkip to conversation

ucm: fix seg fault in execute_cset()

PATCH Applied Lu Guanqun 2 participants 3 messages Aug 19, 2011

lore
Share & tools
lore

Lu Guanqun

author
#0 lore raw

PATCH 1/2 ucm: fix seg fault in execute_cset()

When there's no space in 'cset', 'pos' gets NULL, dereferencing 'pos' gets a seg fault. We need to be more robust.

---
 src/ucm/main.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/ucm/main.c +2 -1
index 8e9a85d..9ecbe43 100644
@@ -196,7 +196,8 @@ static int execute_cset(snd_ctl_t *ctl, char *cset)
 		goto __fail;
 	err = 0;
       __fail:
-	*pos = ' ';
+	if (pos != NULL)
+		*pos = ' ';
 
 	if (id != NULL)
 		free(id);
author
#1 lore raw

PATCH 2/2 ucm: tivial code style fix

---
 src/ucm/main.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/ucm/main.c +1 -1
index 9ecbe43..76ca151 100644
@@ -173,7 +173,7 @@ static int execute_cset(snd_ctl_t *ctl, char *cset)
 	pos = strrchr(cset, ' ');
 	if (pos == NULL) {
 		uc_error("undefined value for cset >%s<", cset);
-		err =  -EINVAL;
+		err = -EINVAL;
 		goto __fail;
 	}
 	*pos = '\0';
Applied
#2 lore raw
In reply to Lu Guanqun

At Fri, 19 Aug 2011 16:05:25 +0800,

Quoted 5 lines · Lu Guanqun

When there's no space in 'cset', 'pos' gets NULL, dereferencing 'pos' gets a seg fault. We need to be more robust.

Thanks, applied both now.

Takashi

Quoted 19 lines
---
 src/ucm/main.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
src/ucm/main.c +2 -1
index 8e9a85d..9ecbe43 100644
@@ -196,7 +196,8 @@ static int execute_cset(snd_ctl_t *ctl, char *cset)
 		goto __fail;
 	err = 0;
       __fail:
-	*pos = ' ';
+	if (pos != NULL)
+		*pos = ' ';
 
 	if (id != NULL)
 		free(id);