+2004-06-24 Ken Raeburn <raeburn@mit.edu>
+
+ * cc_file.c (krb5_fcc_read_data): Combine stdio and posix versions
+ of code with gratuitous minor differences.
+ (krb5_fcc_read_int32, krb5_fcc_next_cred): Likewise.
+ (krb5_fcc_read_addr): Likewise. Check that filled-in length field
+ matches the value we tried to store (i.e., that type conversion
+ didn't throw away information).
+ (krb5_fcc_read_authdatum): Likewise.
+
2004-06-22 Ken Raeburn <raeburn@mit.edu>
* cc_file.c (my_fopen): Function deleted.
return KRB5_OK;
}
-#ifndef USE_STDIO
- data->data = (char *) malloc((unsigned) data->length+1);
-#else
- data->data = (char *) malloc((unsigned int) data->length+1);
-#endif
+ data->data = (char *) malloc(data->length+1);
if (data->data == NULL)
return KRB5_CC_NOMEM;
CHECK(kret);
if ((int32 & VALID_INT_BITS) != int32) /* Overflow int??? */
return KRB5_CC_NOMEM;
-#ifndef USE_STDIO
- addr->length = (int) int32;
-#else
addr->length = int32;
-#endif
+ /* Length field is "unsigned int", which may be smaller than 32
+ bits. */
+ if (addr->length != int32)
+ return KRB5_CC_NOMEM; /* XXX */
if (addr->length == 0)
return KRB5_OK;
krb5_fcc_data *data = (krb5_fcc_data *)id->data;
krb5_error_code retval;
unsigned char buf[4];
-#ifndef USE_STDIO
krb5_int32 val;
-#endif
if ((data->version == KRB5_FCC_FVNO_1) ||
(data->version == KRB5_FCC_FVNO_2))
retval = krb5_fcc_read(context, id, buf, 4);
if (retval)
return retval;
-#ifndef USE_STDIO
val = buf[0];
val = (val << 8) | buf[1];
val = (val << 8) | buf[2];
val = (val << 8) | buf[3];
*i = val;
-#else
- *i = (((((buf[0] << 8) + buf[1]) << 8 ) + buf[2]) << 8) + buf[3];
-#endif
return 0;
}
}
CHECK(kret);
if ((int32 & VALID_INT_BITS) != int32) /* Overflow int??? */
return KRB5_CC_NOMEM;
-#ifndef USE_STDIO
- a->length = (int) int32;
-#else
a->length = int32;
-#endif
+ /* Value could have gotten truncated if int is smaller than 32
+ bits. */
+ if (a->length != int32)
+ return KRB5_CC_NOMEM; /* XXX */
if (a->length == 0 )
return KRB5_OK;
#ifndef USE_STDIO
krb5_ui_2 fcc_fvno;
#else
- char fvno_bytes[2]; /* In nework byte order */
+ char fvno_bytes[2]; /* In network byte order */
#endif
krb5_ui_2 fcc_flen;
krb5_ui_2 fcc_tag;
krb5_fcc_next_cred(krb5_context context, krb5_ccache id, krb5_cc_cursor *cursor, krb5_creds *creds)
{
#define TCHECK(ret) if (ret != KRB5_OK) goto lose;
-#ifdef USE_STDIO
- int ret;
-#endif
krb5_error_code kret;
krb5_fcc_cursor *fcursor;
krb5_int32 int32;
fcursor = (krb5_fcc_cursor *) *cursor;
#ifndef USE_STDIO
- kret = lseek(((krb5_fcc_data *) id->data)->file, fcursor->pos, SEEK_SET);
- if (kret < 0) {
- kret = krb5_fcc_interpret(context, errno);
- MAYBE_CLOSE(context, id, kret);
- return kret;
- }
+ kret = (lseek(((krb5_fcc_data *) id->data)->file, fcursor->pos, SEEK_SET) == (off_t) -1);
#else
- ret = fseek(((krb5_fcc_data *) id->data)->file, fcursor->pos, 0);
- if (ret < 0) {
+ kret = (fseek(((krb5_fcc_data *) id->data)->file, fcursor->pos, 0) < 0);
+#endif
+ if (kret) {
kret = krb5_fcc_interpret(context, errno);
MAYBE_CLOSE(context, id, kret);
return kret;
}
-#endif
kret = krb5_fcc_read_principal(context, id, &creds->client);
TCHECK(kret);