Mercurial > hg-old > index.cgi
changeset 395:54499b799779
Q&D sanitization of symbols in map files and error messages in lwlink
author | lost@l-w.ca |
---|---|
date | Fri, 23 Jul 2010 16:40:51 -0600 |
parents | a2f52e97b454 |
children | 62cb50c50976 |
files | lwlink/link.c lwlink/lwlink.c lwlink/lwlink.h lwlink/map.c |
diffstat | 4 files changed, 43 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lwlink/link.c Fri Jul 23 16:23:54 2010 -0600 +++ b/lwlink/link.c Fri Jul 23 16:40:51 2010 -0600 @@ -286,7 +286,7 @@ } // not found symerr = 1; - fprintf(stderr, "Local symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name); + fprintf(stderr, "Local symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name); goto outerr; } else @@ -311,7 +311,7 @@ } if (sect) { - fprintf(stderr, "External symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name); + fprintf(stderr, "External symbol %s not found in %s:%s\n", sanitize_symbol(sym), sect -> file -> filename, sect -> name); } else { @@ -414,7 +414,7 @@ s = resolve_sym(linkscript.execsym, 0, NULL); if (!s) { - fprintf(stderr, "Cannot resolve exec address '%s'\n", linkscript.execsym); + fprintf(stderr, "Cannot resolve exec address '%s'\n", sanitize_symbol(linkscript.execsym)); symerr = 1; } }
--- a/lwlink/lwlink.c Fri Jul 23 16:23:54 2010 -0600 +++ b/lwlink/lwlink.c Fri Jul 23 16:40:51 2010 -0600 @@ -105,3 +105,40 @@ scriptls = lw_realloc(scriptls, sizeof(char *) * (nscriptls + 1)); scriptls[nscriptls++] = t; } + +char *sanitize_symbol(char *symbol) +{ + static char symbuf[2048]; + char *sym = symbol; + char *tp = symbuf; + + for (; *sym; sym++) + { + int c1 = *sym; + if (c1 == '\\') + { + *tp++ = '\\'; + *tp++ = '\\'; + continue; + } + if (c1 < 32 || c1 > 126) + { + int c; + *tp++ = '\\'; + c = c1 >> 4; + c += 48; + if (c > 57) + c += 7; + *tp++ = c; + c = c1 & 15; + c += 48; + if (c > 57) + c += 7; + *tp++ = c; + continue; + } + *tp++ = c1; + } + *tp = 0; + return symbuf; +}
--- a/lwlink/lwlink.h Fri Jul 23 16:23:54 2010 -0600 +++ b/lwlink/lwlink.h Fri Jul 23 16:40:51 2010 -0600 @@ -127,6 +127,7 @@ __lwlink_E__ void add_input_library(char *fn); __lwlink_E__ void add_library_search(char *fn); __lwlink_E__ void add_section_base(char *fn); +__lwlink_E__ char *sanitize_symbol(char *sym); #undef __lwlink_E__
--- a/lwlink/map.c Fri Jul 23 16:23:54 2010 -0600 +++ b/lwlink/map.c Fri Jul 23 16:40:51 2010 -0600 @@ -69,7 +69,7 @@ for (sn = 0; sn < nsects; sn++) { fprintf(of, "Section: %s (%s) load at %04X, length %04X\n", - sectlist[sn].ptr -> name, + sanitize_symbol(sectlist[sn].ptr -> name), sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> loadaddress, sectlist[sn].ptr -> codesize @@ -107,7 +107,7 @@ for (ce = slist; ce; ce = ce -> next) { - fprintf(of, "Symbol: %s (%s) = %04X\n", ce -> name, ce -> fn, ce -> addr); + fprintf(of, "Symbol: %s (%s) = %04X\n", sanitize_symbol(ce -> name), ce -> fn, ce -> addr); } if (!std)