Uploaded image for project: 'RHEL'
  1. RHEL
  2. RHEL-5685

stack overflow if cannot unlink $HOME/.sh_history

Details

    • Bug
    • Resolution: Unresolved
    • Normal
    • rhel-8.10
    • rhel-7.9.z, rhel-8.8.0, rhel-9.3.0
    • ksh
    • ksh-20120801-265.el8
    • Normal
    • sst_cs_plumbers
    • ssg_core_services
    • 26
    • 5
    • False
    • Hide

      None

      Show
      None
    • If docs needed, set a value

    Description

      It will also fail the rename in the chunk:

      src/cmd/ksh93/edit/history.c
      """
      unlink(hist_old->histname);
      if(access(hist_old->histname,F_OK) >= 0)
      {
      /* The unlink can fail on windows 95 */
      int fd;
      char *last, *name=hist_old->histname;
      close(sffileno(hist_old->histfp));
      tmpname = (char*)malloc(strlen(name)+14);
      if(last = strrchr(name,'/'))

      { *last = 0; pathtmp(tmpname,name,"hist",NIL(int*)); *last = '/'; }

      else
      pathtmp(tmpname,".","hist",NIL(int*));
      if(rename(name,tmpname) < 0)

      { free(tmpname); tmpname = name; }

      fd = open(tmpname,O_RDONLY);
      sfsetfd(hist_old->histfp,fd);
      if(tmpname==name)
      tmpname = 0;
      }
      hist_ptr = 0;
      if(fstat(sffileno(hist_old->histfp),&statb)>=0)

      { histinit = 1; histmode = statb.st_mode; }

      """

      Another condition required is to have a full .sh_history.
      This will cause sh_histinit to call hist_trim, that will
      again call sh_histinit.

      On the backtrace, the condition is verified in the statb
      local variable of hist_trim, where the call trace shows that
      the unlink and rename syscalls failed.
      The unlink call may fail due to a stale file or some filesystem
      issue. The rename call will fail if tmpname is on another filesystem;
      could be nfs vs local filesystem or local filesystem and a tmpfs /tmp.

      The issue only happens if the unlink fails, but still, could use
      a smarter or fallback approach to not cause the stack overflow crash.

      Attachments

        Activity

          People

            kvolny Karel Volný
            rhn-support-pandrade Paulo Andrade
            Vincent Mihalkovic Vincent Mihalkovic
            Karel Volný Karel Volný
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated: