Use strdup(3) instead of reimplementing it inline.
This commit is contained in:
parent
f053d7777b
commit
8d3c1246b8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78711
@ -475,25 +475,19 @@ extract_ugid(const char *str, struct mtpt_info *mip)
|
|||||||
{
|
{
|
||||||
char *ug; /* Writable 'str'. */
|
char *ug; /* Writable 'str'. */
|
||||||
char *user, *group; /* Result of extracton. */
|
char *user, *group; /* Result of extracton. */
|
||||||
size_t strl; /* Length of 'str' incl. NULL. */
|
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
char *p;
|
char *p;
|
||||||
uid_t *uid;
|
uid_t *uid;
|
||||||
gid_t *gid;
|
gid_t *gid;
|
||||||
size_t rv;
|
|
||||||
|
|
||||||
uid = &mip->mi_uid;
|
uid = &mip->mi_uid;
|
||||||
gid = &mip->mi_gid;
|
gid = &mip->mi_gid;
|
||||||
mip->mi_have_uid = mip->mi_have_gid = false;
|
mip->mi_have_uid = mip->mi_have_gid = false;
|
||||||
|
|
||||||
/* Extract the user and group from 'str'. Format above. */
|
/* Extract the user and group from 'str'. Format above. */
|
||||||
strl = strlen(str) + 1;
|
ug = strdup(str);
|
||||||
ug = malloc(strl);
|
|
||||||
assert(ug != NULL);
|
assert(ug != NULL);
|
||||||
rv = strlcpy(ug, str, strl);
|
|
||||||
if (rv >= strl)
|
|
||||||
errx(1, "-w word too long (%ld >= %ld)", (long)rv, (long)strl);
|
|
||||||
group = ug;
|
group = ug;
|
||||||
user = strsep(&group, ":");
|
user = strsep(&group, ":");
|
||||||
if (user == NULL || group == NULL || *user == '\0' || *group == '\0')
|
if (user == NULL || group == NULL || *user == '\0' || *group == '\0')
|
||||||
|
Loading…
Reference in New Issue
Block a user