This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

eggdrop core dump on Solaris 2.7 and 2.9 (solution included)

Discussion of Eggdrop's code and module programming in C.
Post Reply
d
dioid
Voice
Posts: 2
Joined: Sun Jan 30, 2005 1:21 am
Location: Sweden

eggdrop core dump on Solaris 2.7 and 2.9 (solution included)

Post by dioid »

Hi!

I have downloaded eggdrop 1.6.17 from ftp.eggheads.org and compiled it under Solaris 2.7 as well as 2.9. The problem is that the bot dumps core when trying to share user files shortly after trying to link to the hub bot.

By running gdb on the core file I found that the segmentation violation occurs in make_rand_str() which gets an erroneous string length (way too large). I think this happens when the bot generates a random password for the first time when it's linking to hub. It all boils down to randint() not working properly.

I have verified that you get results out of range from randint() by using the tcl command rand.

The problem is that RAND_MAX is 32767 which is max value that rand() returns, but random() is used and on Solaris random() will return an integer in the range 0 to 2**31 - 1.

By modifying the definition of randint() macro in main.h, changing RAND_MAX to 2147483647 (=2**31 - 1) it works as intended and I get no core dumps. Specifically the change is to change the row

#define randint(n) (unsigned long) (random() / (RAND_MAX + 1.0) * ((n) < 0 ? (-(n)) : (n)))

into

#define randint(n) (unsigned long) (random() / (2147483647 + 1.0) * ((n) < 0 ? (-(n)) : (n)))

This problem can be solved by either including a check for Solaris when using random() and not use RAND_MAX or by simply using rand() all the time.

Please let me know if I misunderstood anything.

Thanks,
dioid@EFNet
G
Galadhrim
Op
Posts: 123
Joined: Fri Apr 11, 2003 8:38 am
Location: Netherlands, Enschede

Post by Galadhrim »

As far as I know it is the only way to get things fixed. Solaris has alot of different settings and function definitions than other Unix variant.

If the eggdrop's ./configure sets a define for the operating system you can use that define in any of your eggdrop's source files and recompile. That way if you would ever move the eggdrop to another Unix variant you won't have to edit the sources again.

There is a define for SunOS 4 in the config.h file

Code: Select all

/* Define if running on SunOS 4.0. */
/* #undef DLOPEN_1 */
Maybe you can make a check yourself in the aclocal.m4 file. Something like this:

Code: Select all

dnl EGG_CHECK_OS()
dnl
dnl Various operating system tests.
dnl
AC_DEFUN([EGG_CHECK_OS],
[
  MOD_CC="$CC"
  MOD_LD="$CC"
  MOD_STRIP="$STRIP"
  SHLIB_CC="$CC"
  SHLIB_LD="$CC"
  SHLIB_STRIP="$STRIP"
  LINUX="no"
  IRIX="no"
  SUNOS="no"
  HPUX="no"
  EGG_CYGWIN="no"

  case "$egg_cv_var_system_type" in
    BSD/OS)
      case "`echo $egg_cv_var_system_release | cut -d . -f 1`" in
        2)
          # Fallthrough.
        ;;
        3)
          MOD_CC="shlicc"
          MOD_LD="shlicc"
          if test ! "$STRIP" = "touch"; then
            MOD_STRIP="$STRIP -d"
          fi
          SHLIB_LD="shlicc -r"
          SHLIB_STRIP="touch"
        ;;
        *)
          if test ! "$STRIP" = "touch"; then
            MOD_STRIP="$STRIP -d"
          fi
          SHLIB_CC="$CC -export-dynamic -fPIC"
          SHLIB_LD="$CC -shared -nostartfiles"
        ;;
      esac
    ;;
    CYGWI*)
      AC_PROG_CC_WIN32
      SHLIB_LD="$CC -shared"
      CC="$CC $WIN32FLAGS"
      MOD_CC="$CC"
      MOD_LD="$CC"
      EGG_CYGWIN="yes"
      EGG_CYGWIN_BINMODE
      AC_DEFINE(CYGWIN_HACKS, 1, [Define if running under Cygwin.])
    ;;
    HP-UX)
      HPUX="yes"
      if test "$CC" = "cc"; then
        # HP-UX ANSI C Compiler.
        MOD_LD="$CC +z"
        SHLIB_CC="$CC +z"
      else
        # GCC
        MOD_LD="$CC -fPIC -shared"
        SHLIB_CC="$CC -fPIC"
      fi
      SHLIB_LD="ld -b"
    ;;
    dell)
      SHLIB_STRIP="touch"
      MOD_LD="$CC -lelf -lucb"
    ;;
    IRIX)
      SHLIB_LD="ld -n32 -shared -rdata_shared"
      IRIX="yes"
      SHLIB_STRIP="touch"
    ;;
    Ultrix)
      SHLIB_STRIP="touch"
      DEFAULT_MAKE="static"
      SHELL="/bin/sh5"
    ;;
    SINIX*)
      SHLIB_STRIP="touch"
      SHLIB_CC="cc -G"
    ;;
    BeOS)
      # Fallthrough.
    ;;
    Linux)
      LINUX="yes"
      MOD_LD="$CC"
      SHLIB_CC="$CC -fPIC"
      SHLIB_LD="$CC -shared -nostartfiles"
    ;;
    Lynx)
      # Fallthrough.
    ;;
    QNX)
      SHLIB_LD="ld -shared"
    ;;
    OSF1)
      case "`echo $egg_cv_var_system_release | cut -d . -f 1`" in
        V*)
          # Digital OSF uses an ancient version of gawk
          if test "$AWK" = "gawk"; then
            AWK="awk"
          fi
          SHLIB_LD="ld -shared -expect_unresolved \"'*'\""
          SHLIB_STRIP="touch"
        ;;
        1.0|1.1|1.2)
          SHLIB_LD="ld -R -export $@:"
        ;;
        1.*)
          SHLIB_CC="$CC -fpic"
          SHLIB_LD="ld -shared"
        ;;
      esac
      AC_DEFINE(BROKEN_SNPRINTF, 1, [Define to use Eggdrop's snprintf functions regardless of HAVE_SNPRINTF.])
      AC_DEFINE(STOP_UAC, 1, [Define if running on OSF/1 platform.])
    ;;
    SunOS)
      if test "`echo $egg_cv_var_system_release | cut -d . -f 1`" = "5"; then
        # Solaris
        if test -n "$GCC"; then
          SHLIB_CC="$CC -fPIC"
          SHLIB_LD="$CC -shared"
        else
          SHLIB_CC="$CC -KPIC"
          SHLIB_LD="$CC -G -z text"
        fi
      else
        # SunOS 4
        SUNOS="yes"
        SHLIB_LD="ld"
        SHLIB_CC="$CC -PIC"
      fi
    ;;
    *BSD)
      # FreeBSD/OpenBSD/NetBSD
      SHLIB_CC="$CC -fPIC"
      SHLIB_LD="ld -Bshareable -x"
    ;;
    Darwin)
      # Mac OS X
      SHLIB_CC="$CC -fPIC"
      SHLIB_LD="ld -bundle -undefined error"
    ;;
    *)
      if test -r /mach; then
        # At this point, we're guessing this is NeXT Step.
        AC_DEFINE(BORGCUBES, 1, [Define if running on NeXT Step.])
      else
        if test -r /cmds; then
          # Probably QNX.
          SHLIB_LD="ld -shared"
          SHLIB_STRIP="touch"
        fi
      fi
    ;;
  esac

  AC_SUBST(MOD_LD)
  AC_SUBST(MOD_CC)
  AC_SUBST(MOD_STRIP)
  AC_SUBST(SHLIB_LD)
  AC_SUBST(SHLIB_CC)
  AC_SUBST(SHLIB_STRIP)
])
That way you only have to say ./configure and it's all fixed for your current Unix variant. If it works well try suggesting it to the eggheads and maybe they like the approach and theyll add it to the next version.

Imo it's good to to make a sort of check during ./configure that allows developers to use defines everywhere to make the eggdrop platform independant. Thus far it ok-ish, but problems like these will scare off people with less knowledge of C...

Sorry for the long post, I hoped it would make nice scrolling code boxes :roll:
m
mike503
Voice
Posts: 1
Joined: Wed Jun 15, 2005 10:08 pm

Post by mike503 »

i've been suffering from this problem for the past many eggdrop versions.

in fact, i couldn't even run a bot on that machine. but thanks to this info, i can. i tried a while ago to google for help but got nowhere.

this should be part of the next release of the eggdrop code!

works like a charm now.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

mike503 wrote: this should be part of the next release of the eggdrop code!
make sure it would, let the development team know about this, they don't follow these forums
d
dioid
Voice
Posts: 2
Joined: Sun Jan 30, 2005 1:21 am
Location: Sweden

Post by dioid »

I posted this to eggheads mailing list. Got a reply that a fix has been included in CVS build. So I downloaded lastest v1.6 nightly CVS snapshot and compiled, and it works fine. So I'm pretty sure it will be included in next release.
Post Reply