Changeset 59cce22 in mainline


Ignore:
Timestamp:
2018-12-29T20:37:25Z (6 years ago)
Author:
Jakub Jermář <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
68f1254c
Parents:
6371eb47
git-author:
Matthieu Riolo <matthieu.riolo@…> (2018-12-28 20:53:29)
git-committer:
Jakub Jermář <jakub@…> (2018-12-29 20:37:25)
Message:

Prevents 'ls -r' from crashing when executed in an empty directory

This fixes #779 by adding an extra test around realloc().
The current implementation of realloc() releases the given pointer
and returns NULL if the new requested size is 0. This behavior is
implementation-defined and has been changed with d802331. The
function ls_scan_dir() expected NULL to be returned only in
case of an allocation failure. Therefore, the function
ls_scan_dir() used to display an CL_ENOMEM error and returned
back to ls_recursive(). ls_recursive() would attempt to release
the already freed pointer a second time which would lead
bdsh to break. This commit will prevent this from happening by
avoiding the realloc() call in the first place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r6371eb47 r59cce22  
    199199
    200200        /* Populate the directory list. */
    201         if (ls.recursive) {
     201        if (ls.recursive && nbdirs > 0) {
    202202                tmp = (struct dir_elem_t *) realloc(*dir_list_ptr,
    203203                    nbdirs * sizeof(struct dir_elem_t));
Note: See TracChangeset for help on using the changeset viewer.