Bug 162526 - Sigbus in net/minidlna port because read_random_bytes treats size_t as signed
Summary: Sigbus in net/minidlna port because read_random_bytes treats size_t as signed
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Mikhail Teterin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-13 18:50 UTC by Wes Santee
Modified: 2011-12-26 00:38 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wes Santee 2011-11-13 18:50:10 UTC
The patch for the net/minidlna port replaces read_random_bytes in uuid.c.  However, the while loop in the replaced function treats the size_t variable 'size' as signed, causing the while loop break condition to fail, which then causes a sigbus.

Fix: 

In uuid.c, replace:


read_random_bytes(unsigned char *buf, size_t size)
{
        long r;
        srandomdev();

        while (size > 0) {
                r = random();
                memcpy(buf, &r,
                    size > sizeof(r) ? sizeof(r) : size);
                buf += sizeof(r);
                size -= sizeof(r);
        }
}

with (note cast in while loop):


read_random_bytes(unsigned char *buf, size_t size)
{
        long r;
        srandomdev();

        while ((ssize_t)size > 0) {
                r = random();
                memcpy(buf, &r,
                    size > sizeof(r) ? sizeof(r) : size);
                buf += sizeof(r);
                size -= sizeof(r);
        }
}

Or, fix the buf and size arithmetic within the while loop to prevent 'size' from going below zero.
How-To-Repeat: Run minidlna port (possibly only happens on amd64 host).
Comment 1 dfilter service freebsd_committer freebsd_triage 2011-12-22 19:12:57 UTC
mi          2011-12-22 19:12:41 UTC

  FreeBSD ports repository

  Modified files:
    net/minidlna         Makefile 
    net/minidlna/files   BSDmakefile patch-aa 
  Log:
  Cast a size_t variable to ssize_t to prevent negatives being interpreted
  as huge positives. Bump PORTREVISION.
  
  Explicitly turn off the "deprecated-declarations" warning, which allows
  to delete the NO_WERROR setting from BSDmakefile.
  
  PR:     162526
  Submitted by:   Wes Santee
  
  Revision  Changes    Path
  1.5       +1 -0      ports/net/minidlna/Makefile
  1.4       +1 -2      ports/net/minidlna/files/BSDmakefile
  1.3       +1 -1      ports/net/minidlna/files/patch-aa
_______________________________________________
cvs-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/cvs-all
To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
Comment 2 Mark Linimon freebsd_committer freebsd_triage 2011-12-26 00:37:30 UTC
State Changed
From-To: open->closed

already committed. 


Comment 3 Mark Linimon freebsd_committer freebsd_triage 2011-12-26 00:37:30 UTC
Responsible Changed
From-To: freebsd-ports-bugs->mi