projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
date and time created 83/02/11 15:44:24 by rrh
[unix-history]
/
usr
/
src
/
usr.bin
/
ranlib
/
ranlib.c
diff --git
a/usr/src/usr.bin/ranlib/ranlib.c
b/usr/src/usr.bin/ranlib/ranlib.c
index
3ee68a9
..
3266a53
100644
(file)
--- a/
usr/src/usr.bin/ranlib/ranlib.c
+++ b/
usr/src/usr.bin/ranlib/ranlib.c
@@
-1,4
+1,4
@@
-static char sccsid[] = "@(#)ranlib.c
3.2
%G%";
+static char sccsid[] = "@(#)ranlib.c
4.4
%G%";
/*
* ranlib - create table of contents for archive; string table version
*/
/*
* ranlib - create table of contents for archive; string table version
*/
@@
-16,10
+16,10
@@
struct exec exp;
FILE *fi, *fo;
long off, oldoff;
long atol(), ftell();
FILE *fi, *fo;
long off, oldoff;
long atol(), ftell();
-#define TABSZ
2
000
+#define TABSZ
5
000
struct ranlib tab[TABSZ];
int tnum;
struct ranlib tab[TABSZ];
int tnum;
-#define STRTABSZ
2
5000
+#define STRTABSZ
7
5000
char tstrtab[STRTABSZ];
int tssiz;
char *strtab;
char tstrtab[STRTABSZ];
int tssiz;
char *strtab;
@@
-32,7
+32,9
@@
main(argc, argv)
char **argv;
{
char cmdbuf[BUFSIZ];
char **argv;
{
char cmdbuf[BUFSIZ];
- char magbuf[SARMAG+1];
+ /* magbuf must be an int array so it is aligned on an int-ish
+ boundary, so that we may access its first word as an int! */
+ int magbuf[(SARMAG+sizeof(int))/sizeof(int)];
--argc;
while(argc--) {
--argc;
while(argc--) {
@@
-42,9
+44,9
@@
char **argv;
continue;
}
off = SARMAG;
continue;
}
off = SARMAG;
- fread(magbuf, 1, SARMAG, fi);
- if (strncmp(magbuf, ARMAG, SARMAG)) {
- if (
*(int *)magbuf
== OARMAG)
+ fread(
(char *)
magbuf, 1, SARMAG, fi);
+ if (strncmp(
(char *)
magbuf, ARMAG, SARMAG)) {
+ if (
magbuf[0]
== OARMAG)
fprintf(stderr, "old format ");
else
fprintf(stderr, "not an ");
fprintf(stderr, "old format ");
else
fprintf(stderr, "not an ");
@@
-67,7
+69,7
@@
char **argv;
continue;
if (exp.a_syms == 0) {
fprintf(stderr, "ranlib: warning: %s(%s): no symbol table\n", *argv, archdr.ar_name);
continue;
if (exp.a_syms == 0) {
fprintf(stderr, "ranlib: warning: %s(%s): no symbol table\n", *argv, archdr.ar_name);
-
exit(1)
;
+
continue
;
}
o = N_STROFF(exp) - sizeof (struct exec);
if (ftell(fi)+o+sizeof(ssiz) >= off) {
}
o = N_STROFF(exp) - sizeof (struct exec);
if (ftell(fi)+o+sizeof(ssiz) >= off) {
@@
-76,6
+78,11
@@
char **argv;
}
fseek(fi, o, 1);
fread((char *)&ssiz, 1, sizeof (ssiz), fi);
}
fseek(fi, o, 1);
fread((char *)&ssiz, 1, sizeof (ssiz), fi);
+ if (ssiz < sizeof ssiz){
+ /* sanity check */
+ fprintf(stderr, "ranlib: %s(%s): mangled string table\n", *argv, archdr.ar_name);
+ exit(1);
+ }
strtab = (char *)calloc(1, ssiz);
if (strtab == 0) {
fprintf(stderr, "ranlib: ran out of memory\n");
strtab = (char *)calloc(1, ssiz);
if (strtab == 0) {
fprintf(stderr, "ranlib: ran out of memory\n");