mirror of
https://github.com/openbsd/src.git
synced 2026-06-19 15:53:31 +02:00
Check that string length != 0 before setting buf[strlen(buf) - 1].
OK cloder@.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user