Skip to content

Commit 5f65469

Browse files
PrivacyIsARightDuncaen
authored andcommitted
lib: handle missing colon in alternatives safely
1 parent 839cc37 commit 5f65469

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/package_alternatives.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ left(const char *str)
6060
static const char *
6161
right(const char *str)
6262
{
63-
return strchr(str, ':') + 1;
63+
const char *p = strchr(str, ':');
64+
if (!p)
65+
return NULL;
66+
return p + 1;
6467
}
6568

6669
static const char *
@@ -130,6 +133,7 @@ remove_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname)
130133
const char *tgt;
131134
char *tgt_dup, *tgt_dir;
132135
tgt = right(xbps_string_cstring_nocopy(str));
136+
assert(tgt);
133137
tgt_dup = strdup(tgt);
134138
assert(tgt_dup);
135139
tgt_dir = dirname(tgt_dup);

0 commit comments

Comments
 (0)