Changeset 599a1c7 in mainline for uspace/app/bdsh/cmds/modules/ls/ls.c


Ignore:
Timestamp:
2018-12-29T20:19:00Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Parents:
accdbd8
git-author:
Matthieu Riolo <matthieu.riolo@…> (2018-12-28 20:53:29)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2018-12-29 20:19:00)
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

    raccdbd8 r599a1c7  
    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.