Skip to content

Commit 31ee668

Browse files
committed
lib: fix another null pointer deference in alternative splitting
1 parent d3214b1 commit 31ee668

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

lib/package_alternatives.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@
4747
static char *
4848
left(const char *str)
4949
{
50-
char *p;
51-
size_t len;
50+
char *e;
5251

53-
p = strdup(str);
54-
len = strlen(p) - strlen(strchr(p, ':'));
55-
p[len] = '\0';
52+
e = strchr(str, ':');
53+
if (!e)
54+
return NULL;
5655

57-
return p;
56+
return strndup(str, e - str);
5857
}
5958

6059
static const char *

0 commit comments

Comments
 (0)