On Mon, Jan 5, 2015 at 12:14 AM, tito <[email protected]> wrote:
> 1) in function parse_common count should start at 1 as line numbers are off
> by one.
>
> static char *parse_common(FILE *fp, struct passdb *db,
> const char *key, int field_pos)
> {
> - int count = 0;
> + int count = 1;
> char *buf;
>
> while ((buf = xmalloc_fgetline(fp)) != NULL) {
There is a count++ immediately after we got a line:
int count = 0;
char *buf;
while ((buf = xmalloc_fgetline(fp)) != NULL) {
count++;
> 2) in parse_common the use of key variable seems problematic to me:
>
> if (!key) {
> /* no key specified: sequential read, return a record
> */
> break;
> }
>
> This variable string is passed on from the caller and eventually from the user
> we have no guarantee that it will be non NULL when we don't want a sequential
> read.
> If the calling app passes a bad pointer it will get a record returned.
I think that getpwnam(NULL) is not a valid use, but ok,
we can plug this hole anyway. Switching to field_pos == -1
as "no search" indicator.
> 3) in parse_common function
>
> while ((buf = xmalloc_fgetline(fp)) != NULL) {
>
> does not set errno to ENOENT on EOF
How about this simple fix in getXXent_r()? -
buf = parse_common(db->fp, db, /*no search key:*/ NULL, 0);
+ if (!buf && !errno)
+ errno = ENOENT;
return massage_data_for_r_func(db, buffer, buflen, result, buf);
Thanks!
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox