Changeset e62f8e3 in mainline


Ignore:
Timestamp:
2019-06-23T17:43:50Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
46288ee
Parents:
0d0f1a8
Message:

Adding a maximal loop counter for nested aliases

This commit was requested by a a reviewer. The old
version allowed to have endless nested aliases. This
commit changes this allowing only 20 nested aliases.

Location:
uspace/app/bdsh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/config.h

    r0d0f1a8 re62f8e3  
    4242#endif
    4343
     44/* define maximal nested aliases */
     45#ifndef HUBS_MAX
     46#define HUBS_MAX 20
     47#endif
     48
    4449/* Used in many places */
    4550#define SMALL_BUFLEN 256
  • uspace/app/bdsh/input.c

    r0d0f1a8 re62f8e3  
    8686 * the handler
    8787 */
    88 static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups)
    89 {
     88static errno_t process_input_nohup(cliuser_t *usr, list_t *alias_hups, size_t count_executed_hups)
     89{
     90        if (count_executed_hups >= HUBS_MAX) {
     91                cli_error(CL_EFAIL, "%s: maximal alias hubs reached\n", PACKAGE_NAME);
     92                return ELIMIT;
     93        }
     94
    9095        token_t *tokens_buf = calloc(WORD_MAX, sizeof(token_t));
    9196        if (tokens_buf == NULL)
     
    197202                if (!find_alias_hup(data, alias_hups)) {
    198203                        alias_hup_t *hup = (alias_hup_t *)calloc(1, sizeof(alias_hup_t));
     204                        if (hup == NULL) {
     205                                cli_error(CL_EFAIL, "%s: cannot allocate alias structure\n", PACKAGE_NAME);
     206                                rc = ENOMEM;
     207                                goto finit;
     208                        }
     209
    199210                        hup->alias = data;
    200211                        list_append(&hup->alias_hup_link, alias_hups);
     
    202213                        char *oldLine = usr->line;
    203214                        const size_t input_length = str_size(usr->line) - str_size(cmd[0]) + str_size(data->value) + 1;
    204                         usr->line = (char *)malloc(input_length * sizeof(char));
     215                        usr->line = (char *)malloc(input_length);
     216                        if (usr->line == NULL) {
     217                                cli_error(CL_EFAIL, "%s: cannot allocate input structure\n", PACKAGE_NAME);
     218                                rc = ENOMEM;
     219                                goto finit;
     220                        }
     221
    205222                        usr->line[0] = '\0';
    206223
     
    222239
    223240                        /* reprocess input after string replace */
    224                         rc = process_input_nohup(usr, alias_hups);
     241                        rc = process_input_nohup(usr, alias_hups, count_executed_hups + 1);
    225242                        usr->line = oldLine;
    226243                        goto finit;
     
    287304        list_initialize(&alias_hups);
    288305
    289         errno_t rc = process_input_nohup(usr, &alias_hups);
     306        errno_t rc = process_input_nohup(usr, &alias_hups, 0);
    290307
    291308        list_foreach_safe(alias_hups, cur_link, next_link) {
Note: See TracChangeset for help on using the changeset viewer.