diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-03 21:03:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-01-03 21:03:39 +0100 |
commit | f9936676bb7fd57ea2256af2247c970d1ed3f906 (patch) | |
tree | e9dbc12b458c72c04478d7f1620b5f11d600782d /libpwdgrp | |
parent | 134c53098bdcbf7a0c34b60b97c46280d86eb48f (diff) | |
download | busybox-w32-f9936676bb7fd57ea2256af2247c970d1ed3f906.tar.gz busybox-w32-f9936676bb7fd57ea2256af2247c970d1ed3f906.tar.bz2 busybox-w32-f9936676bb7fd57ea2256af2247c970d1ed3f906.zip |
libpwdgrp: fix counting of commas in group list
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libpwdgrp')
-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 4b61b61d2..01058d3a1 100644 --- a/libpwdgrp/pwd_grp.c +++ b/libpwdgrp/pwd_grp.c | |||
@@ -203,22 +203,6 @@ static char *parse_common(FILE *fp, const char *filename, | |||
203 | bb_error_msg("bad record at %s:%u", filename, count); | 203 | bb_error_msg("bad record at %s:%u", filename, count); |
204 | goto free_and_next; | 204 | goto free_and_next; |
205 | } | 205 | } |
206 | S.string_size = S.tokenize_end - buf; | ||
207 | |||
208 | /* Ugly hack: group db requires additional buffer space | ||
209 | * for members[] array. If there is only one group, we need space | ||
210 | * for 3 pointers: alignment padding, group name, NULL. | ||
211 | * +1 for every additional group. | ||
212 | */ | ||
213 | if (n_fields == sizeof(GR_DEF)-1) { /* if we read group file */ | ||
214 | int cnt = 3; | ||
215 | char *p = buf; | ||
216 | while (*p) | ||
217 | if (*p++ == ',') | ||
218 | cnt++; | ||
219 | S.string_size += cnt * sizeof(char*); | ||
220 | buf = xrealloc(buf, S.string_size); | ||
221 | } | ||
222 | 206 | ||
223 | if (!key) { | 207 | if (!key) { |
224 | /* no key specified: sequential read, return a record */ | 208 | /* no key specified: sequential read, return a record */ |
@@ -232,6 +216,24 @@ static char *parse_common(FILE *fp, const char *filename, | |||
232 | free(buf); | 216 | free(buf); |
233 | } | 217 | } |
234 | 218 | ||
219 | S.string_size = S.tokenize_end - buf; | ||
220 | /* | ||
221 | * Ugly hack: group db requires additional buffer space | ||
222 | * for members[] array. If there is only one group, we need space | ||
223 | * for 3 pointers: alignment padding, group name, NULL. | ||
224 | * +1 for every additional group. | ||
225 | */ | ||
226 | if (n_fields == sizeof(GR_DEF)-1) { /* if we read group file... */ | ||
227 | int cnt = 3; | ||
228 | char *p = buf; | ||
229 | while (p < S.tokenize_end) | ||
230 | if (*p++ == ',') | ||
231 | cnt++; | ||
232 | S.string_size += cnt * sizeof(char*); | ||
233 | //bb_error_msg("+%d words = %u key:%s buf:'%s'", cnt, S.string_size, key, buf); | ||
234 | buf = xrealloc(buf, S.string_size); | ||
235 | } | ||
236 | |||
235 | return buf; | 237 | return buf; |
236 | } | 238 | } |
237 | 239 | ||