Changeset 88057e3 in mainline


Ignore:
Timestamp:
2012-01-23T16:22:40Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a6240a31
Parents:
9d09d7f
Message:

fix a nasty bug that could force loc_get_categories() to go into an infinite loop
note that the the loop is still unbounded, but it should not cause any real trouble

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/loc.c

    r9d09d7f r88057e3  
    795795    sysarg_t **data, size_t *count)
    796796{
    797         service_id_t *ids;
    798         size_t act_size;
    799         size_t alloc_size;
    800         int rc;
    801 
    802797        *data = NULL;
    803         act_size = 0;   /* silence warning */
    804 
    805         rc = loc_category_get_ids_once(method, arg1, NULL, 0,
     798        *count = 0;
     799       
     800        size_t act_size = 0;
     801        int rc = loc_category_get_ids_once(method, arg1, NULL, 0,
    806802            &act_size);
    807803        if (rc != EOK)
    808804                return rc;
    809 
    810         alloc_size = act_size;
    811         ids = malloc(alloc_size);
     805       
     806        size_t alloc_size = act_size;
     807        service_id_t *ids = malloc(alloc_size);
    812808        if (ids == NULL)
    813809                return ENOMEM;
    814 
     810       
    815811        while (true) {
    816812                rc = loc_category_get_ids_once(method, arg1, ids, alloc_size,
     
    818814                if (rc != EOK)
    819815                        return rc;
    820 
    821                 if (act_size <= alloc_size)
     816               
     817                if (alloc_size <= act_size)
    822818                        break;
    823 
    824                 alloc_size *= 2;
    825                 free(ids);
    826 
    827                 ids = malloc(alloc_size);
     819               
     820                alloc_size = act_size;
     821                ids = realloc(ids, alloc_size);
    828822                if (ids == NULL)
    829823                        return ENOMEM;
    830824        }
    831 
     825       
    832826        *count = act_size / sizeof(category_id_t);
    833827        *data = ids;
Note: See TracChangeset for help on using the changeset viewer.