#include "internal/ctype.h"
#include "internal/constant_time_locl.h"
#include "e_os.h"
+#include "err_locl.h"
static int err_load_strings(const ERR_STRING_DATA *str);
}
#endif
-#define err_get_slot(p) \
- do { \
- (p)->top = ((p)->top + 1) % ERR_NUM_ERRORS; \
- if ((p)->top == (p)->bottom) \
- (p)->bottom = ((p)->bottom + 1) % ERR_NUM_ERRORS; \
- } while (0)
-
-#define err_clear_data(p, i, deall) \
- do { \
- if ((p)->err_data_flags[i] & ERR_TXT_MALLOCED) { \
- if (deall) { \
- OPENSSL_free((p)->err_data[i]); \
- (p)->err_data[i] = NULL; \
- (p)->err_data_size[i] = 0; \
- (p)->err_data_flags[i] = 0; \
- } else if ((p)->err_data[i] != NULL) { \
- (p)->err_data[i][0] = '\0'; \
- } \
- } else { \
- (p)->err_data[i] = NULL; \
- (p)->err_data_size[i] = 0; \
- (p)->err_data_flags[i] = 0; \
- } \
- } while (0)
-
-#define err_clear(p, i, deall) \
- do { \
- err_clear_data((p), (i), (deall)); \
- (p)->err_flags[i] = 0; \
- (p)->err_buffer[i] = 0; \
- (p)->err_file[i] = NULL; \
- (p)->err_line[i] = -1; \
- } while (0)
-
static void ERR_STATE_free(ERR_STATE *s)
{
int i;
/********************************************************/
-void ERR_put_func_error(int lib, const char *func, int reason,
- const char *file, int line)
-{
- ERR_put_error(lib, 0, reason, file, line);
- ERR_add_error_data(2, "calling function ", func);
-}
-
-void ERR_put_error(int lib, int func, int reason, const char *file, int line)
-{
- ERR_STATE *es;
-
-#ifdef _OSD_POSIX
- /*
- * In the BS2000-OSD POSIX subsystem, the compiler generates path names
- * in the form "*POSIX(/etc/passwd)". This dirty hack strips them to
- * something sensible. @@@ We shouldn't modify a const string, though.
- */
- if (strncmp(file, "*POSIX(", sizeof("*POSIX(") - 1) == 0) {
- char *end;
-
- /* Skip the "*POSIX(" prefix */
- file += sizeof("*POSIX(") - 1;
- end = &file[strlen(file) - 1];
- if (*end == ')')
- *end = '\0';
- /* Optional: use the basename of the path only. */
- if ((end = strrchr(file, '/')) != NULL)
- file = &end[1];
- }
-#endif
- es = ERR_get_state();
- if (es == NULL)
- return;
-
- err_get_slot(es);
- err_clear(es, es->top, 0);
- es->err_buffer[es->top] = ERR_PACK(lib, func, reason);
- es->err_file[es->top] = file;
- es->err_line[es->top] = line;
-}
-
void ERR_clear_error(void)
{
int i;
int deallocate)
{
ERR_STATE *es;
- int i;
es = ERR_get_state();
if (es == NULL)
return 0;
- i = es->top;
-
err_clear_data(es, es->top, deallocate);
- es->err_data[i] = data;
- es->err_data_size[i] = size;
- es->err_data_flags[i] = flags;
+ err_set_data(es, es->top, data, size, flags);
return 1;
}
}
len = strlen(str);
- for (len = 0; --num >= 0; ) {
+ while (--num >= 0) {
arg = va_arg(args, char *);
if (arg == NULL)
arg = "<NULL>";
len += strlen(arg);
- if (len > size) {
+ if (len >= size) {
char *p;
size = len + 20;
- p = OPENSSL_realloc(str, size + 1);
+ p = OPENSSL_realloc(str, size);
if (p == NULL) {
OPENSSL_free(str);
return;
}
str = p;
}
- OPENSSL_strlcat(str, arg, (size_t)size + 1);
+ OPENSSL_strlcat(str, arg, (size_t)size);
}
if (!err_set_error_data_int(str, size, flags, 0))
OPENSSL_free(str);