ref: 39dff9f7b0cb26421d0b67fc003fdda8db867e0b
parent: 88ed18b6b1014546e25583c8d2372ba8030e1bf8
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 20 03:27:19 EST 2019
[ld] Solves several problems in the main loop of loadlib() The code could generate infinite loops in the way that it was written and the condition for the definition of the symbol was the opposite.
--- a/src/cmd/ld.c
+++ b/src/cmd/ld.c
@@ -341,32 +341,31 @@
return;
}
- for (loaded = 0; moreundef(); loaded = 0) {
+ for (loaded = 1; moreundef() && loaded; ) {
+ loaded = 0;
for (dp = def; dp; dp = dp->next) {
sym = lookup(dp->name, NOINSTALL);
- if (!sym || !sym->def)
+ if (!sym || sym->def)
continue;
if (fseek(fp, dp->offset, SEEK_SET) == EOF) {
error(errstr());
- break;
+ goto clean;
}
if ((t = objtype(fp, NULL)) == -1) {
error("library file corrupted");
- break;
+ goto clean;
}
if (t != bintype) {
error("incompatible library");
- break;
+ goto clean;
}
newobject(fp, t, OUTLIB);
loaded = 1;
}
- if (!loaded)
- break;
}
clean:
free(def);