summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2006-10-16 21:19:56 +0000
committerRay Lai <ray@cvs.openbsd.org>2006-10-16 21:19:56 +0000
commit3bc285ffc6a40b59756a81be5b84e38a94cd4835 (patch)
tree8578083be18dd8311b57498593ec9bc31a6a92e4
parent8f6c590f9f0fbde88d0febe61c8be654c5ea0c85 (diff)
Check that string length != 0 before setting buf[strlen(buf) - 1].
OK cloder@.
-rw-r--r--kerberosV/src/kadmin/add-random-users.c8
-rw-r--r--kerberosV/src/kdc/string2key.c4
-rw-r--r--kerberosV/src/kpasswd/kpasswd-generator.c2
-rw-r--r--kerberosV/src/kuser/generate-requests.c2
-rw-r--r--kerberosV/src/lib/kadm5/ipropd_master.c2
-rw-r--r--kerberosV/src/lib/krb5/config_file.c4
-rw-r--r--kerberosV/src/lib/sl/sl.c2
7 files changed, 13 insertions, 11 deletions
diff --git a/kerberosV/src/kadmin/add-random-users.c b/kerberosV/src/kadmin/add-random-users.c
index 364e63d2817..3a84de9acc3 100644
--- a/kerberosV/src/kadmin/add-random-users.c
+++ b/kerberosV/src/kadmin/add-random-users.c
@@ -57,13 +57,15 @@ read_words (const char *filename, char ***ret_w)
while (fgets (buf, sizeof(buf), f) != NULL) {
size_t len;
- if (buf[strlen (buf) - 1] == '\n')
- buf[strlen (buf) - 1] = '\0';
+ len = strlen(buf);
+ if (len != 0 && buf[len - 1] == '\n') {
+ buf[len - 1] = '\0';
+ --len;
+ }
if (n >= alloc) {
alloc = max(alloc + 16, alloc * 2);
w = erealloc (w, alloc * sizeof(char **));
}
- len = strlen(buf);
if (wptr + len + 1 >= wend) {
wptr = wbuf = emalloc (WORDBUF_SIZE);
wend = wbuf + WORDBUF_SIZE;
diff --git a/kerberosV/src/kdc/string2key.c b/kerberosV/src/kdc/string2key.c
index ecd0d8e9020..72a9b49c9ed 100644
--- a/kerberosV/src/kdc/string2key.c
+++ b/kerberosV/src/kdc/string2key.c
@@ -161,7 +161,7 @@ main(int argc, char **argv)
printf("Kerberos v5 principal: ");
if(fgets(buf, sizeof(buf), stdin) == NULL)
return 1;
- if(buf[strlen(buf) - 1] == '\n')
+ if(buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
principal = estrdup(buf);
}
@@ -169,7 +169,7 @@ main(int argc, char **argv)
printf("AFS cell: ");
if(fgets(buf, sizeof(buf), stdin) == NULL)
return 1;
- if(buf[strlen(buf) - 1] == '\n')
+ if(buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
cell = estrdup(buf);
}
diff --git a/kerberosV/src/kpasswd/kpasswd-generator.c b/kerberosV/src/kpasswd/kpasswd-generator.c
index 6d45160383d..c080fa708e6 100644
--- a/kerberosV/src/kpasswd/kpasswd-generator.c
+++ b/kerberosV/src/kpasswd/kpasswd-generator.c
@@ -48,7 +48,7 @@ read_words (const char *filename, char ***ret_w)
err (1, "cannot open %s", filename);
alloc = n = 0;
while (fgets (buf, sizeof(buf), f) != NULL) {
- if (buf[strlen (buf) - 1] == '\n')
+ if (buf[0] != '\0' && buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (n >= alloc) {
alloc += 16;
diff --git a/kerberosV/src/kuser/generate-requests.c b/kerberosV/src/kuser/generate-requests.c
index 748f589bcc9..70380fae44e 100644
--- a/kerberosV/src/kuser/generate-requests.c
+++ b/kerberosV/src/kuser/generate-requests.c
@@ -58,7 +58,7 @@ read_words (const char *filename, char ***ret_w)
err (1, "cannot open %s", filename);
alloc = n = 0;
while (fgets (buf, sizeof(buf), f) != NULL) {
- if (buf[strlen (buf) - 1] == '\n')
+ if (buf[0] != '\0' && buf[strlen (buf) - 1] == '\n')
buf[strlen (buf) - 1] = '\0';
if (n >= alloc) {
alloc += 16;
diff --git a/kerberosV/src/lib/kadm5/ipropd_master.c b/kerberosV/src/lib/kadm5/ipropd_master.c
index 3c4fee3c594..4e9e00dd06e 100644
--- a/kerberosV/src/lib/kadm5/ipropd_master.c
+++ b/kerberosV/src/lib/kadm5/ipropd_master.c
@@ -127,7 +127,7 @@ check_acl (krb5_context context, const char *name)
if (fp == NULL)
return 1;
while (fgets(buf, sizeof(buf), fp) != NULL) {
- if (buf[strlen(buf) - 1 ] == '\n')
+ if (buf[0] != '\0' && buf[strlen(buf) - 1 ] == '\n')
buf[strlen(buf) - 1 ] = '\0';
if (strcmp (buf, name) == 0) {
ret = 0;
diff --git a/kerberosV/src/lib/krb5/config_file.c b/kerberosV/src/lib/krb5/config_file.c
index 5194aff1ca6..3c400539ff8 100644
--- a/kerberosV/src/lib/krb5/config_file.c
+++ b/kerberosV/src/lib/krb5/config_file.c
@@ -158,7 +158,7 @@ parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent,
char *p;
++*lineno;
- if (buf[strlen(buf) - 1] == '\n')
+ if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
p = buf;
while(isspace((unsigned char)*p))
@@ -255,7 +255,7 @@ krb5_config_parse_debug (struct fileptr *f,
char *p;
++*lineno;
- if(buf[strlen(buf) - 1] == '\n')
+ if(buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
p = buf;
while(isspace((unsigned char)*p))
diff --git a/kerberosV/src/lib/sl/sl.c b/kerberosV/src/lib/sl/sl.c
index c45877f2f1d..fd1125d7ef3 100644
--- a/kerberosV/src/lib/sl/sl.c
+++ b/kerberosV/src/lib/sl/sl.c
@@ -214,7 +214,7 @@ readline(char *prompt)
fflush (stdout);
if(fgets(buf, sizeof(buf), stdin) == NULL)
return NULL;
- if (buf[strlen(buf) - 1] == '\n')
+ if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
return strdup(buf);
}