~ubuntu-branches/ubuntu/saucy/m2crypto/saucy

« back to all changes in this revision

Viewing changes to SWIG/_objects.i

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 01:28:39 UTC
  • mfrom: (2.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091106012839-zjjugwmj8zggokqh
Tags: 0.20.1-1ubuntu1
* Merge from debian testing, remaining changes:
  - debian/rules; enable testsuite, add more files to "clean" rule.
  - tests/test_ssl.py: use signal 9 to kill old s_server processes
    to work around build HUP signal-ignore-mask (LP: #451998).

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
%inline %{
44
44
/*
45
 
    Following code is working but man page declare that it won't
46
 
    OBJ_obj2txt(3SSL). OpenSSL 0.9.8e
47
 
    BUGS
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.
54
 
 
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)
57
 
 
58
 
446         if ((a == NULL) || (a->data == NULL)) {
59
 
447                 buf[0]='\0';
60
 
448                 return(0);
61
 
449         }
62
 
 
63
 
    Since NULL pointer is guarded by SWIG this condition may not occur.
64
 
 
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.
68
 
 */
 
45
   From the manpage for OBJ_obt2txt ():
 
46
   BUGS
 
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.
 
53
 
 
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.
 
57
 
 
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.
 
61
*/
69
62
PyObject *obj_obj2txt(const ASN1_OBJECT *obj, int no_name)
70
63
{
71
64
    int len;
72
65
    PyObject *ret;
73
66
    char *buf;
 
67
    char dummy[1];
74
68
 
75
 
    len = OBJ_obj2txt(0, 0, obj, no_name);
 
69
    len = OBJ_obj2txt(dummy, 1, obj, no_name);
76
70
    if (len < 0) {
77
71
        PyErr_SetString(PyExc_RuntimeError, ERR_reason_error_string(ERR_get_error()));
78
72
        return NULL;
 
73
    } else if (len == 0) {
 
74
        /* XXX: For OpenSSL prior to 0.9.8b.
 
75
 
 
76
          Changes between 0.9.8a and 0.9.8b  [04 May 2006]
 
77
          ...
 
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.
 
82
             [Steve Henson]
 
83
        */
 
84
 
 
85
        len = 80;
79
86
    }
80
87
 
81
88
    buf = PyMem_Malloc(len + 1);