Changeset 32

Show
Ignore:
Timestamp:
05/29/08 20:42:07 (6 months ago)
Author:
jtang
Message:

Fixed potential buffer overflow where the size of the reading buffer is incorrectly calculated.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/src/mqueue_internal.c

    r30 r32  
    22* 
    33* Copyright (C) 2006, 2007 Tresys Technology, LLC 
    4 * Developed Under US JFCOM Sponsorship  
     4* Developed Under US JFCOM Sponsorship 
    55* 
    66*  This library is free software; you can redistribute it and/or 
     
    3434#define MQ_PERMS 0666 
    3535 
    36 /* Create a message queue having the specified key.  
     36/* Create a message queue having the specified key. 
    3737 * This function should only be called by a helper application 
    3838 * and not by the sender or reciever. */ 
     
    4040{ 
    4141        int msqid; 
    42          
     42 
    4343        msqid = msgget(key, MQ_PERMS|IPC_CREAT|IPC_EXCL); 
    4444        if (msqid < 0) 
    45                 fprintf(stderr, "msgget: %s\n", strerror(errno));               
     45                fprintf(stderr, "msgget: %s\n", strerror(errno)); 
    4646 
    4747        return msqid; 
     
    6060                return; 
    6161        } 
    62          
    63         if (msgctl(msqid, IPC_RMID, NULL) < 0)  
    64                 fprintf(stderr, "msgctl: %s\n", strerror(errno));       
     62 
     63        if (msgctl(msqid, IPC_RMID, NULL) < 0) 
     64                fprintf(stderr, "msgctl: %s\n", strerror(errno)); 
    6565} 
    6666 
     
    7979                return -1; 
    8080        } 
    81          
     81 
    8282        msqid = msgget(key, flags); 
    8383        if (msqid < 0) { 
     
    8585                return -1; 
    8686        } 
    87          
    88         return msqid;           
     87 
     88        return msqid; 
    8989} 
    9090 
     
    101101        struct msqid_ds mqbuf; 
    102102 
    103         if (msgctl(msqid, IPC_STAT, &mqbuf) < 0)  
     103        if (msgctl(msqid, IPC_STAT, &mqbuf) < 0) 
    104104                return -1; 
    105                  
     105 
    106106        /* Change the capacity of the queue */ 
    107107        mqbuf.msg_qbytes = mqbytes; 
    108         if (msgctl(msqid, IPC_SET, &mqbuf) < 0)  
     108        if (msgctl(msqid, IPC_SET, &mqbuf) < 0) 
    109109                return -1; 
    110110 
     
    120120        int flags = block ? 0 : IPC_NOWAIT; 
    121121 
    122         if (msgrcv(msqid, &mbuf, sizeof(mbuf), type, flags) < 0) { 
     122        if (msgrcv(msqid, &mbuf, sizeof(mbuf.mtext), type, flags) < 0) { 
    123123                if (errno == ENOMSG) 
    124124                        return 0; 
    125         }       
    126          
     125        } 
     126 
    127127        return mbuf.mtype; 
    128128} 
     
    137137 
    138138        mbuf.mtype = type; 
    139         bzero(mbuf.mtext, 1);   
    140         if (msgsnd(msqid, &mbuf, sizeof(mbuf), flags) < 0)  
     139        memset(mbuf.mtext, 1, sizeof(mbuf.mtext)); 
     140        if (msgsnd(msqid, &mbuf, sizeof(mbuf.mtext), flags) < 0) 
    141141                return -1; 
    142142 
    143143        return 0; 
    144144} 
    145