Changeset 311bc25 in mainline for kernel/generic/src/sysinfo/sysinfo.c


Ignore:
Timestamp:
2011-01-25T17:09:04Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a0ce870
Parents:
8befd0a
Message:

avoid the possibility for infinite looping on fetching sysinfo values
still make the tests in statistical functions more robust
this fixes ticket #237

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/sysinfo/sysinfo.c

    r8befd0a r311bc25  
    4040#include <arch/asm.h>
    4141#include <errno.h>
     42#include <macros.h>
    4243
    4344/** Maximal sysinfo path length */
     
    761762 * character must be null).
    762763 *
    763  * The user space buffer must be sized exactly according
    764  * to the size of the binary data, otherwise the request
    765  * fails.
     764 * If the user space buffer size does not equal
     765 * the actual size of the returned data, the data
     766 * is truncated. Whether this is actually a fatal
     767 * error or the data can be still interpreted as valid
     768 * depends on the nature of the data and has to be
     769 * decided by the user space.
     770 *
     771 * The actual size of data returned is stored to
     772 * size_ptr.
    766773 *
    767774 * @param path_ptr    Sysinfo path in the user address space.
     
    770777 *                    to store the binary data.
    771778 * @param buffer_size User space buffer size.
     779 * @param size_ptr    User space pointer where to store the
     780 *                    binary data size.
    772781 *
    773782 * @return Error code (EOK in case of no error).
     
    775784 */
    776785sysarg_t sys_sysinfo_get_data(void *path_ptr, size_t path_size,
    777     void *buffer_ptr, size_t buffer_size)
     786    void *buffer_ptr, size_t buffer_size, size_t *size_ptr)
    778787{
    779788        int rc;
    780789       
    781790        /* Get the item */
    782         sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    783 
     791        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size,
     792            false);
     793       
    784794        /* Only constant or generated binary data is considered */
    785         if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
    786                 /* Check destination buffer size */
    787                 if (ret.data.size == buffer_size)
    788                         rc = copy_to_uspace(buffer_ptr, ret.data.data,
    789                             ret.data.size);
    790                 else
    791                         rc = ENOMEM;
     795        if ((ret.tag == SYSINFO_VAL_DATA) ||
     796            (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     797                size_t size = min(ret.data.size, buffer_size);
     798                rc = copy_to_uspace(buffer_ptr, ret.data.data, size);
     799                if (rc == EOK)
     800                        rc = copy_to_uspace(size_ptr, &size, sizeof(size));
    792801        } else
    793802                rc = EINVAL;
Note: See TracChangeset for help on using the changeset viewer.