| 1 |
/* |
| 2 |
Copyright (C) 2000-2004 Silicon Graphics, Inc. All Rights Reserved. |
| 3 |
Portions Copyright (C) 2009-2020 David Anderson. All Rights Reserved. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it |
| 6 |
and/or modify it under the terms of version 2.1 of the |
| 7 |
GNU Lesser General Public License as published by the Free |
| 8 |
Software Foundation. |
| 9 |
|
| 10 |
This program is distributed in the hope that it would be |
| 11 |
useful, but WITHOUT ANY WARRANTY; without even the implied |
| 12 |
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 13 |
PURPOSE. |
| 14 |
|
| 15 |
Further, this software is distributed without any warranty |
| 16 |
that it is free of the rightful claim of any third person |
| 17 |
regarding infringement or the like. Any license provided |
| 18 |
herein, whether implied or otherwise, applies only to this |
| 19 |
software file. Patent licenses, if any, provided herein |
| 20 |
do not apply to combinations of this program with other |
| 21 |
software, or any other product whatsoever. |
| 22 |
|
| 23 |
You should have received a copy of the GNU Lesser General |
| 24 |
Public License along with this program; if not, write the |
| 25 |
Free Software Foundation, Inc., 51 Franklin Street - Fifth |
| 26 |
Floor, Boston MA 02110-1301, USA. |
| 27 |
|
| 28 |
*/ |
| 29 |
|
| 30 |
#include <config.h> |
| 31 |
|
| 32 |
#include <stddef.h> /* NULL, size_t */ |
| 33 |
#include <string.h> /* strlen() */ |
| 34 |
|
| 35 |
#if defined(_WIN32) && defined(HAVE_STDAFX_H) |
| 36 |
#include "stdafx.h" |
| 37 |
#endif /* HAVE_STDAFX_H */ |
| 38 |
|
| 39 |
#include "dwarf.h" |
| 40 |
#include "libdwarf.h" |
| 41 |
#include "libdwarf_private.h" |
| 42 |
#include "dwarf_base_types.h" |
| 43 |
#include "dwarf_opaque.h" |
| 44 |
#include "dwarf_error.h" |
| 45 |
#include "dwarf_util.h" |
| 46 |
|
| 47 |
int |
| 48 |
dwarf_get_str(Dwarf_Debug dbg, |
| 49 |
Dwarf_Off offset, |
| 50 |
char **string, |
| 51 |
Dwarf_Signed * returned_str_len, Dwarf_Error * error) |
| 52 |
{ |
| 53 |
int res = DW_DLV_ERROR; |
| 54 |
void *secptr = 0; |
| 55 |
void *begin = 0; |
| 56 |
void *end = 0; |
| 57 |
|
| 58 |
CHECK_DBG(dbg,error,"dwarf_get_str()"); |
| 59 |
if (offset == dbg->de_debug_str.dss_size) { |
| 60 |
/* Normal (if we've iterated thru the set of strings using |
| 61 |
dwarf_get_str and are at the end). */ |
| 62 |
return DW_DLV_NO_ENTRY; |
| 63 |
} |
| 64 |
if (offset > dbg->de_debug_str.dss_size) { |
| 65 |
_dwarf_error(dbg, error, DW_DLE_DEBUG_STR_OFFSET_BAD); |
| 66 |
return DW_DLV_ERROR; |
| 67 |
} |
| 68 |
|
| 69 |
if (!string || !returned_str_len) { |
| 70 |
_dwarf_error(dbg, error, DW_DLE_STRING_PTR_NULL); |
| 71 |
return DW_DLV_ERROR; |
| 72 |
} |
| 73 |
|
| 74 |
res = _dwarf_load_section(dbg, &dbg->de_debug_str,error); |
| 75 |
if (res != DW_DLV_OK) { |
| 76 |
return res; |
| 77 |
} |
| 78 |
if (!dbg->de_debug_str.dss_size) { |
| 79 |
return DW_DLV_NO_ENTRY; |
| 80 |
} |
| 81 |
secptr =dbg->de_debug_str.dss_data; |
| 82 |
begin = (char *)secptr + offset; |
| 83 |
end = (char *)secptr + dbg->de_debug_str.dss_size; |
| 84 |
|
| 85 |
res = _dwarf_check_string_valid(dbg,secptr,begin,end, |
| 86 |
DW_DLE_DEBUG_STR_OFFSET_BAD,error); |
| 87 |
if (res != DW_DLV_OK) { |
| 88 |
return res; |
| 89 |
} |
| 90 |
|
| 91 |
*string = (char *) begin; |
| 92 |
*returned_str_len = strlen(*string); |
| 93 |
return DW_DLV_OK; |
| 94 |
} |