From 5e5385184e58bdf7eaa492547c696d3b10f0185a Mon Sep 17 00:00:00 2001 From: John Kohl Date: Tue, 12 Feb 1991 14:03:41 +0000 Subject: [PATCH] properly deal with errno on short read/write git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1669 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/ccache/stdio/scc_read.c | 15 ++++++++++----- src/lib/krb5/ccache/stdio/scc_write.c | 20 +++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/lib/krb5/ccache/stdio/scc_read.c b/src/lib/krb5/ccache/stdio/scc_read.c index 790a3779f..62515dc03 100644 --- a/src/lib/krb5/ccache/stdio/scc_read.c +++ b/src/lib/krb5/ccache/stdio/scc_read.c @@ -36,8 +36,9 @@ krb5_scc_read(id, buf, len) { int ret; + errno = 0; ret = fread((char *) buf, 1, len, ((krb5_scc_data *) id->data)->file); - if (ret == 0) + if ((ret == 0) && errno) return krb5_scc_interpret(errno); else if (ret != len) return KRB5_CC_END; @@ -166,11 +167,12 @@ krb5_scc_read_keyblock(id, keyblock) if (keyblock->contents == NULL) return KRB5_CC_NOMEM; + errno = 0; ret = fread((char *)keyblock->contents, 1, (keyblock->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret == 0) { + if ((ret == 0) && errno) { xfree(keyblock->contents); return krb5_scc_interpret(errno); } @@ -203,9 +205,10 @@ krb5_scc_read_data(id, data) if (data->data == NULL) return KRB5_CC_NOMEM; + errno = 0; ret = fread((char *)data->data, 1, data->length, ((krb5_scc_data *) id->data)->file); - if (ret == -1) { + if ((ret == 0) && errno) { xfree(data->data); return krb5_scc_interpret(errno); } @@ -240,9 +243,10 @@ krb5_scc_read_addr(id, addr) if (addr->contents == NULL) return KRB5_CC_NOMEM; + errno = 0; ret = fread((char *)addr->contents, 1, (addr->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret == -1) { + if ((ret == 0) && errno) { xfree(addr->contents); return krb5_scc_interpret(errno); } @@ -373,10 +377,11 @@ krb5_scc_read_authdatum(id, a) a->contents = (krb5_octet *) malloc(a->length); if (a->contents == NULL) return KRB5_CC_NOMEM; + errno = 0; ret = fread ((char *)a->contents, 1, (a->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret == 0) { + if ((ret == 0) && errno) { xfree(a->contents); return krb5_scc_interpret(errno); } diff --git a/src/lib/krb5/ccache/stdio/scc_write.c b/src/lib/krb5/ccache/stdio/scc_write.c index e180437cc..78409be4e 100644 --- a/src/lib/krb5/ccache/stdio/scc_write.c +++ b/src/lib/krb5/ccache/stdio/scc_write.c @@ -38,10 +38,12 @@ krb5_scc_write(id, buf, len) { int ret; + errno = 0; ret = fwrite((char *) buf, 1, len, ((krb5_scc_data *)id->data)->file); - if (ret == 0) { + if ((ret == 0) && errno) { return krb5_scc_interpret (errno); - } + } else if (ret != len) + return KRB5_CC_END; return KRB5_OK; } @@ -118,10 +120,11 @@ krb5_scc_store_keyblock(id, keyblock) CHECK(ret); ret = krb5_scc_store_int(id, &keyblock->length); CHECK(ret); + errno = 0; ret = fwrite((char *)keyblock->contents, 1, (keyblock->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret == 0) + if ((ret == 0) && errno) return krb5_scc_interpret(errno); if (ret != (keyblock->length)*sizeof(krb5_octet)) return KRB5_CC_END; @@ -140,10 +143,11 @@ krb5_scc_store_addr(id, addr) CHECK(ret); ret = krb5_scc_store_int(id, &addr->length); CHECK(ret); + errno = 0; ret = fwrite((char *)addr->contents, 1, (addr->length)*sizeof(krb5_octet), ((krb5_scc_data *) id->data)->file); - if (ret == 0) + if ((ret == 0) && errno) return krb5_scc_interpret(errno); if (ret != (addr->length)*sizeof(krb5_octet)) return KRB5_CC_END; @@ -160,11 +164,13 @@ krb5_scc_store_data(id, data) ret = krb5_scc_store_int32(id, &data->length); CHECK(ret); + errno = 0; ret = fwrite(data->data, 1, data->length, ((krb5_scc_data *) id->data)->file); - if (ret == 0) + if ((ret == 0) && errno) return krb5_scc_interpret(errno); - + else if (ret != data->length) + return KRB5_CC_END; return KRB5_OK; } @@ -257,5 +263,5 @@ krb5_scc_store_authdatum (id, a) CHECK(ret); ret = krb5_scc_store_int32(id, &a->length); CHECK(ret); - return krb5_scc_write(id, a->contents, a->length); + return krb5_scc_write(id, (krb5_pointer) a->contents, a->length); } -- 2.26.2