From 02d86aafe8164b38956e3bacad1d3a3364bd4e66 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 11 Feb 2014 07:43:13 -0700 Subject: [PATCH] When emulating DSO_NEXT with shl_get() we need to skip the program's handle. This used to be documented as being index -2 but now it seems to be index 0. As this is not guaranteed we need to look up the real handle value for PROG_HANDLE and skip it when interating through all the DSOs. Fixes infinite recursion on HP-UX in the getenv() replacement. --- common/sudo_dso.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/sudo_dso.c b/common/sudo_dso.c index 6e71c597f..44f060400 100644 --- a/common/sudo_dso.c +++ b/common/sudo_dso.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012-2013 Todd C. Miller + * Copyright (c) 2010, 2012-2014 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -131,9 +131,16 @@ sudo_dso_findsym(void *vhandle, const char *symbol) */ if (vhandle == SUDO_DSO_NEXT) { /* Iterate over all shared libs looking for symbol. */ + shl_t myhandle = PROG_HANDLE; struct shl_descriptor *desc; int idx = 0; + + /* Find program's real handle. */ + if (shl_gethandle(PROG_HANDLE, &desc) == 0) + myhandle = desc->handle; while (shl_get(idx++, &desc) == 0) { + if (desc->handle == myhandle) + continue; if (shl_findsym(&desc->handle, symbol, TYPE_UNDEFINED, &value) == 0) break; }