1 /* $OpenBSD: main.c,v 1.3 2005/09/17 00:31:59 kurt Exp $ */ 2 3 /* 4 * Copyright (c) 2005 Kurt Miller <kurt@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <dlfcn.h> 20 #include <stdio.h> 21 22 int mainSymbol; 23 24 /* 25 * This tests that the main object group can not see the symbols in 26 * objects dlopened by it using RTLD_{SELF,NEXT}, NULL and with a handle. 27 */ 28 int 29 main() 30 { 31 int ret = 0; 32 void *exe_handle = dlopen(NULL, RTLD_LAZY); 33 void *libbb = dlopen("libbb.so", RTLD_LAZY); 34 35 if (libbb == NULL) { 36 printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n"); 37 return (1); 38 } 39 40 /* RTLD_DEFAULT should *not* see bbSymbol */ 41 if (dlsym(RTLD_DEFAULT, "bbSymbol") != NULL) { 42 printf("dlsym(RTLD_DEFAULT, \"bbSymbol\") != NULL\n"); 43 ret = 1; 44 } 45 46 /* RTLD_SELF should *not* see bbSymbol (different load group) */ 47 if (dlsym(RTLD_SELF, "bbSymbol") != NULL) { 48 printf("dlsym(RTLD_SELF, \"bbSymbol\") != NULL\n"); 49 ret = 1; 50 } 51 52 /* RTLD_NEXT should *not* see bbSymbol (different load group) */ 53 if (dlsym(RTLD_NEXT, "bbSymbol") != NULL) { 54 printf("dlsym(RTLD_NEXT, \"bbSymbol\") != NULL\n"); 55 ret = 1; 56 } 57 58 /* NULL should *not* see bbSymbol (different load group) */ 59 if (dlsym(NULL, "bbSymbol") != NULL) { 60 printf("dlsym(NULL, \"bbSymbol\") != NULL\n"); 61 ret = 1; 62 } 63 64 /* exe handle should *not* see bbSymbol (different load group) */ 65 if (dlsym(exe_handle, "bbSymbol") != NULL) { 66 printf("dlsym(exe_handle, \"bbSymbol\") != NULL\n"); 67 ret = 1; 68 } 69 70 dlclose(exe_handle); 71 dlclose(libbb); 72 73 return (ret); 74 } 75