[Rpm-maint] [rpm-software-management/rpm] rpmio.c: In Fread(buf, size, nmemb, FD), require size be 1 (#400)

Alexey Tourbin notifications at github.com
Fri Feb 23 21:37:12 UTC 2018


It seems that Fread returns the number of bytes read, as opposed
to the number of items, each size bytes long.  The relevant comment
in rpmio.h says that Fread is "fread(3) clone" (which implies that
the number of items should be returned).

This breaks the following idiomatic code which used to work with rpm-4.0:
```c
    char buf[110];
    if (Fread(buf, 110, 1, cpio->fd) != 1)
	die("%s: cannot read cpio header", cpio->rpmbname);
```
The program dies with "cannot read cpio header", while in fact Fread
returns 110.  It seems that the only way to reconcile the number of
bytes and the number of items is to require that size be 1.  Indeed,
I would much prefer an assertion failure.

This change breaks the existing code which calls Fread with nmemb=1
and expects the number of bytes to be returned.
You can view, comment on, or merge this pull request online at:

  https://github.com/rpm-software-management/rpm/pull/400

-- Commit Summary --

  * rpmio.c: In Fread(buf,size,nmemb,FD), require size be 1

-- File Changes --

    M rpmio/rpmio.c (9)

-- Patch Links --

https://github.com/rpm-software-management/rpm/pull/400.patch
https://github.com/rpm-software-management/rpm/pull/400.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/400
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20180223/602c8cb7/attachment.html>


More information about the Rpm-maint mailing list