45
Following code is working but man page declare that it won't
46
OBJ_obj2txt(3SSL). OpenSSL 0.9.8e
48
OBJ_obj2txt() is awkward and messy to use: it doesn’t follow the
49
convention of other OpenSSL functions where the buffer can be set
50
to NULL to determine the amount of data that should be written.
51
Instead buf must point to a valid buffer and buf_len should be set
52
to a positive value. A buffer length of 80 should be more than
53
enough to handle any OID encountered in practice.
55
But code (crypto/objects/obj_dat.c near line 438) has only one place
56
where buf is not checked (when object pointer is NULL)
58
446 if ((a == NULL) || (a->data == NULL)) {
63
Since NULL pointer is guarded by SWIG this condition may not occur.
65
OBJ_obj2txt always prints \0 at the end. But return value
66
is amount of "good" bytes written. So memory is allocated for
67
len + 1 bytes but only len bytes are marshalled to python.
45
From the manpage for OBJ_obt2txt ():
47
OBJ_obj2txt() is awkward and messy to use: it doesn’t follow the
48
convention of other OpenSSL functions where the buffer can be set
49
to NULL to determine the amount of data that should be written.
50
Instead buf must point to a valid buffer and buf_len should be set
51
to a positive value. A buffer length of 80 should be more than
52
enough to handle any OID encountered in practice.
54
The first call to OBJ_obj2txt () therefore passes a non-NULL dummy
55
buffer. This wart is reportedly removed in OpenSSL 0.9.8b, although
56
the manpage has not been updated.
58
OBJ_obj2txt always prints \0 at the end. But the return value
59
is the number of "good" bytes written. So memory is allocated for
60
len + 1 bytes but only len bytes are marshalled to python.
69
62
PyObject *obj_obj2txt(const ASN1_OBJECT *obj, int no_name)
75
len = OBJ_obj2txt(0, 0, obj, no_name);
69
len = OBJ_obj2txt(dummy, 1, obj, no_name);
77
71
PyErr_SetString(PyExc_RuntimeError, ERR_reason_error_string(ERR_get_error()));
73
} else if (len == 0) {
74
/* XXX: For OpenSSL prior to 0.9.8b.
76
Changes between 0.9.8a and 0.9.8b [04 May 2006]
78
*) Several fixes and enhancements to the OID generation code. The old code
79
sometimes allowed invalid OIDs (1.X for X >= 40 for example), couldn't
80
handle numbers larger than ULONG_MAX, truncated printing and had a
81
non standard OBJ_obj2txt() behaviour.
81
88
buf = PyMem_Malloc(len + 1);