merge strcpy_truncate branch

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@5027 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1998-06-09 19:25:40 +00:00
parent e255dfc950
commit a5f54865d4
87 changed files with 689 additions and 499 deletions

View File

@@ -26,6 +26,14 @@ Thu Feb 12 11:20:15 1998 Johan Danielsson <joda@emma.pdc.kth.se>
* Makefile.in: Install/uninstall one library at a time.
Thu Feb 12 05:38:58 1998 Assar Westerlund <assar@sics.se>
* Makefile.in (install): one library at a time.
Mon Feb 9 23:40:32 1998 Assar Westerlund <assar@sics.se>
* common.c (find_cells): ignore empty lines
Tue Jan 6 04:25:58 1998 Assar Westerlund <assar@sics.se>
* afssysdefs.h (AFS_SYSCALL): add FreeBSD

View File

@@ -87,9 +87,10 @@ static char *
get_realm(kafs_data *data, const char *host)
{
char *r = krb_realmofhost(host);
if(r)
if(r != NULL)
return strdup(r);
return NULL;
else
return NULL;
}
int
@@ -97,6 +98,7 @@ krb_afslog_uid(const char *cell, const char *realm, uid_t uid)
{
kafs_data kd;
struct krb_kafs_data d;
kd.afslog_uid = afslog_uid_int;
kd.get_cred = get_cred;
kd.get_realm = get_realm;

View File

@@ -63,7 +63,7 @@ aix_setup(void)
* If we are root or running setuid don't trust AFSLIBPATH!
*/
if (getuid() != 0 && !issuid() && (p = getenv("AFSLIBPATH")) != NULL)
snprintf(path, sizeof(path), "%s", p);
strcpy_truncate(path, p, sizeof(path));
else
snprintf(path, sizeof(path), "%s/afslib.so", LIBDIR);

View File

@@ -79,7 +79,7 @@
#define AFS_SYSCALL 31
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define AFS_SYSCALL 210
#endif

View File

@@ -155,8 +155,9 @@ dns_find_cell(const char *cell, char *dbserver, size_t len)
struct resource_record *rr = r->head;
while(rr){
if(rr->type == T_AFSDB && rr->u.afsdb->preference == 1){
strncpy(dbserver, rr->u.afsdb->domain, len);
dbserver[len - 1] = '\0';
strcpy_truncate(dbserver,
rr->u.afsdb->domain,
len);
ok = 0;
break;
}
@@ -184,7 +185,10 @@ find_cells(char *file, char ***cells, int *index)
return;
while (fgets(cell, sizeof(cell), f)) {
char *nl = strchr(cell, '\n');
if (nl) *nl = 0;
if (nl)
*nl = '\0';
if (cell[0] == '\0')
continue;
for(i = 0; i < ind; i++)
if(strcmp((*cells)[i], cell) == 0)
break;

View File

@@ -115,14 +115,12 @@ void *dlopen(const char *path, int mode)
}
if ((mp = (ModulePtr)calloc(1, sizeof(*mp))) == NULL) {
errvalid++;
strcpy(errbuf, "calloc: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, "calloc: %s", strerror(errno));
return NULL;
}
if ((mp->name = strdup(path)) == NULL) {
errvalid++;
strcpy(errbuf, "strdup: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, "strdup: %s", strerror(errno));
free(mp);
return NULL;
}
@@ -134,9 +132,8 @@ void *dlopen(const char *path, int mode)
free(mp->name);
free(mp);
errvalid++;
strcpy(errbuf, "dlopen: ");
strcat(errbuf, path);
strcat(errbuf, ": ");
snprintf (errbuf, sizeof(errbuf),
"dlopen: %s: ", path);
/*
* If AIX says the file is not executable, the error
* can be further described by querying the loader about
@@ -145,14 +142,18 @@ void *dlopen(const char *path, int mode)
if (errno == ENOEXEC) {
char *tmp[BUFSIZ/sizeof(char *)];
if (loadquery(L_GETMESSAGES, tmp, sizeof(tmp)) == -1)
strcpy(errbuf, strerror(errno));
strcpy_truncate(errbuf,
strerror(errno),
sizeof(errbuf));
else {
char **p;
for (p = tmp; *p; p++)
caterr(*p);
}
} else
strcat(errbuf, strerror(errno));
strcat_truncate(errbuf,
strerror(errno),
sizeof(errbuf));
return NULL;
}
mp->refCnt = 1;
@@ -161,8 +162,8 @@ void *dlopen(const char *path, int mode)
if (loadbind(0, mainModule, mp->entry) == -1) {
dlclose(mp);
errvalid++;
strcpy(errbuf, "loadbind: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"loadbind: %s", strerror(errno));
return NULL;
}
/*
@@ -175,8 +176,9 @@ void *dlopen(const char *path, int mode)
if (loadbind(0, mp1->entry, mp->entry) == -1) {
dlclose(mp);
errvalid++;
strcpy(errbuf, "loadbind: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"loadbind: %s",
strerror(errno));
return NULL;
}
}
@@ -229,29 +231,29 @@ static void caterr(char *s)
p++;
switch(atoi(s)) {
case L_ERROR_TOOMANY:
strcat(errbuf, "to many errors");
strcat_truncate(errbuf, "to many errors", sizeof(errbuf));
break;
case L_ERROR_NOLIB:
strcat(errbuf, "can't load library");
strcat(errbuf, p);
strcat_truncate(errbuf, "can't load library", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_UNDEF:
strcat(errbuf, "can't find symbol");
strcat(errbuf, p);
strcat_truncate(errbuf, "can't find symbol", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_RLDBAD:
strcat(errbuf, "bad RLD");
strcat(errbuf, p);
strcat_truncate(errbuf, "bad RLD", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_FORMAT:
strcat(errbuf, "bad exec format in");
strcat(errbuf, p);
strcat_truncate(errbuf, "bad exec format in", sizeof(errbuf));
strcat_truncate(errbuf, p, sizeof(errbuf));
break;
case L_ERROR_ERRNO:
strcat(errbuf, strerror(atoi(++p)));
strcat_truncate(errbuf, strerror(atoi(++p)), sizeof(errbuf));
break;
default:
strcat(errbuf, s);
strcat_truncate(errbuf, s, sizeof(errbuf));
break;
}
}
@@ -270,8 +272,8 @@ void *dlsym(void *handle, const char *symbol)
if (strcmp(ep->name, symbol) == 0)
return ep->addr;
errvalid++;
strcpy(errbuf, "dlsym: undefined symbol ");
strcat(errbuf, symbol);
snprintf (errbuf, sizeof(errbuf),
"dlsym: undefined symbol %s", symbol);
return NULL;
}
@@ -311,7 +313,8 @@ int dlclose(void *handle)
result = unload(mp->entry);
if (result == -1) {
errvalid++;
strcpy(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"%s", strerror(errno));
}
if (mp->exports) {
ExportPtr ep;
@@ -360,8 +363,9 @@ static int readExports(ModulePtr mp)
int size = 4*1024;
if (errno != ENOENT) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf(errbuf, sizeof(errbuf),
"readExports: %s",
strerror(errno));
return -1;
}
/*
@@ -371,8 +375,9 @@ static int readExports(ModulePtr mp)
*/
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf(errbuf, sizeof(errbuf),
"readExports: %s",
strerror(errno));
return -1;
}
while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) {
@@ -380,15 +385,17 @@ static int readExports(ModulePtr mp)
size += 4*1024;
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf(errbuf, sizeof(errbuf),
"readExports: %s",
strerror(errno));
return -1;
}
}
if (i == -1) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf(errbuf, sizeof(errbuf),
"readExports: %s",
strerror(errno));
free(buf);
return -1;
}
@@ -411,14 +418,14 @@ static int readExports(ModulePtr mp)
free(buf);
if (!ldp) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"readExports: %s", strerror(errno));
return -1;
}
}
if (TYPE(ldp) != U802TOCMAGIC) {
errvalid++;
strcpy(errbuf, "readExports: bad magic");
snprintf(errbuf, sizeof(errbuf), "readExports: bad magic");
while(ldclose(ldp) == FAILURE)
;
return -1;
@@ -430,14 +437,16 @@ static int readExports(ModulePtr mp)
*/
if (ldnshread(ldp, _DATA, &shdata) != SUCCESS) {
errvalid++;
strcpy(errbuf, "readExports: cannot read data section header");
snprintf(errbuf, sizeof(errbuf),
"readExports: cannot read data section header");
while(ldclose(ldp) == FAILURE)
;
return -1;
}
if (ldnshread(ldp, _LOADER, &sh) != SUCCESS) {
errvalid++;
strcpy(errbuf, "readExports: cannot read loader section header");
snprintf(errbuf, sizeof(errbuf),
"readExports: cannot read loader section header");
while(ldclose(ldp) == FAILURE)
;
return -1;
@@ -448,15 +457,16 @@ static int readExports(ModulePtr mp)
*/
if ((ldbuf = (char *)malloc(sh.s_size)) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"readExports: %s", strerror(errno));
while(ldclose(ldp) == FAILURE)
;
return -1;
}
if (FSEEK(ldp, sh.s_scnptr, BEGINNING) != OKFSEEK) {
errvalid++;
strcpy(errbuf, "readExports: cannot seek to loader section");
snprintf(errbuf, sizeof(errbuf),
"readExports: cannot seek to loader section");
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
@@ -464,7 +474,8 @@ static int readExports(ModulePtr mp)
}
if (FREAD(ldbuf, sh.s_size, 1, ldp) != 1) {
errvalid++;
strcpy(errbuf, "readExports: cannot read loader section");
snprintf(errbuf, sizeof(errbuf),
"readExports: cannot read loader section");
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
@@ -482,8 +493,8 @@ static int readExports(ModulePtr mp)
}
if ((mp->exports = (ExportPtr)calloc(mp->nExports, sizeof(*mp->exports))) == NULL) {
errvalid++;
strcpy(errbuf, "readExports: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"readExports: %s", strerror(errno));
free(ldbuf);
while(ldclose(ldp) == FAILURE)
;
@@ -508,8 +519,8 @@ static int readExports(ModulePtr mp)
* must copy the first SYMNMLEN chars and make
* sure we have a zero byte at the end.
*/
strncpy(tmpsym, ls->l_name, SYMNMLEN);
tmpsym[SYMNMLEN] = '\0';
strcpy_truncate (tmpsym, ls->l_name,
SYMNMLEN + 1);
symname = tmpsym;
}
ep->name = strdup(symname);
@@ -537,8 +548,8 @@ static void * findMain(void)
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"findMail: %s", strerror(errno));
return NULL;
}
while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) {
@@ -546,15 +557,15 @@ static void * findMain(void)
size += 4*1024;
if ((buf = malloc(size)) == NULL) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"findMail: %s", strerror(errno));
return NULL;
}
}
if (i == -1) {
errvalid++;
strcpy(errbuf, "findMain: ");
strcat(errbuf, strerror(errno));
snprintf (errbuf, sizeof(errbuf),
"findMail: %s", strerror(errno));
free(buf);
return NULL;
}