diff options
author | Denys Vlasenko | 2015-01-03 21:03:39 +0100 |
---|---|---|
committer | Denys Vlasenko | 2015-01-03 21:03:39 +0100 |
commit | f9936676bb7fd57ea2256af2247c970d1ed3f906 (patch) | |
tree | e9dbc12b458c72c04478d7f1620b5f11d600782d /libpwdgrp/pwd_grp.c | |
parent | 134c53098bdcbf7a0c34b60b97c46280d86eb48f (diff) | |
download | busybox-f9936676bb7fd57ea2256af2247c970d1ed3f906.zip busybox-f9936676bb7fd57ea2256af2247c970d1ed3f906.tar.gz |
libpwdgrp: fix counting of commas in group list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libpwdgrp/pwd_grp.c')
-rw-r--r-- | libpwdgrp/pwd_grp.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c index 4b61b61..01058d3 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c @@ -203,22 +203,6 @@ static char *parse_common(FILE *fp, const char *filename, bb_error_msg("bad record at %s:%u", filename, count); goto free_and_next; } - S.string_size = S.tokenize_end - buf; - -/* Ugly hack: group db requires additional buffer space - * for members[] array. If there is only one group, we need space - * for 3 pointers: alignment padding, group name, NULL. - * +1 for every additional group. - */ - if (n_fields == sizeof(GR_DEF)-1) { /* if we read group file */ - int cnt = 3; - char *p = buf; - while (*p) - if (*p++ == ',') - cnt++; - S.string_size += cnt * sizeof(char*); - buf = xrealloc(buf, S.string_size); - } if (!key) { /* no key specified: sequential read, return a record */ @@ -232,6 +216,24 @@ static char *parse_common(FILE *fp, const char *filename, free(buf); } + S.string_size = S.tokenize_end - buf; +/* + * Ugly hack: group db requires additional buffer space + * for members[] array. If there is only one group, we need space + * for 3 pointers: alignment padding, group name, NULL. + * +1 for every additional group. + */ + if (n_fields == sizeof(GR_DEF)-1) { /* if we read group file... */ + int cnt = 3; + char *p = buf; + while (p < S.tokenize_end) + if (*p++ == ',') + cnt++; + S.string_size += cnt * sizeof(char*); +//bb_error_msg("+%d words = %u key:%s buf:'%s'", cnt, S.string_size, key, buf); + buf = xrealloc(buf, S.string_size); + } + return buf; } |