~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to common/membuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * GnuPG is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * the Free Software Foundation; either version 3 of the License, or
9
9
 * (at your option) any later version.
10
10
 *
11
11
 * GnuPG is distributed in the hope that it will be useful,
14
14
 * GNU General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19
18
 */
20
19
 
21
20
#include <config.h>
41
40
  mb->out_of_core = 0;
42
41
  mb->buf = xtrymalloc (initiallen);
43
42
  if (!mb->buf)
44
 
      mb->out_of_core = errno;
 
43
    mb->out_of_core = errno;
 
44
}
 
45
 
 
46
/* Same as init_membuf but allocates the buffer in secure memory.  */
 
47
void
 
48
init_membuf_secure (membuf_t *mb, int initiallen)
 
49
{
 
50
  mb->len = 0;
 
51
  mb->size = initiallen;
 
52
  mb->out_of_core = 0;
 
53
  mb->buf = xtrymalloc_secure (initiallen);
 
54
  if (!mb->buf)
 
55
    mb->out_of_core = errno;
45
56
}
46
57
 
47
58
 
59
70
      p = xtryrealloc (mb->buf, mb->size);
60
71
      if (!p)
61
72
        {
62
 
          mb->out_of_core = errno;
 
73
          mb->out_of_core = errno ? errno : ENOMEM;
63
74
          /* Wipe out what we already accumulated.  This is required
64
75
             in case we are storing sensitive data here.  The membuf
65
76
             API does not provide another way to cleanup after an
74
85
}
75
86
 
76
87
 
 
88
void
 
89
put_membuf_str (membuf_t *mb, const char *string)
 
90
{
 
91
  put_membuf (mb, string, strlen (string));
 
92
}
 
93
 
 
94
 
77
95
void *
78
96
get_membuf (membuf_t *mb, size_t *len)
79
97
{
83
101
    {
84
102
      xfree (mb->buf);
85
103
      mb->buf = NULL;
 
104
      errno = mb->out_of_core;
86
105
      return NULL;
87
106
    }
88
107
 
89
108
  p = mb->buf;
90
 
  *len = mb->len;
 
109
  if (len)
 
110
    *len = mb->len;
91
111
  mb->buf = NULL;
92
112
  mb->out_of_core = ENOMEM; /* hack to make sure it won't get reused. */
93
113
  return p;