~ubuntu-branches/ubuntu/raring/sudo/raring

« back to all changes in this revision

Viewing changes to common/alloc.c

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks
  • Date: 2012-07-16 14:01:42 UTC
  • mfrom: (1.3.22 sid)
  • Revision ID: package-import@ubuntu.com-20120716140142-b0tgau0k6nid4mrf
Tags: 1.8.5p2-1ubuntu1
* Merge from debian/testing (LP: #1024154), remaining changes:
  - debian/patches/keep_home_by_default.patch:
    + Set HOME in initial_keepenv_table.
  - debian/rules:
    + compile with --without-lecture --with-tty-tickets (Ubuntu specific)
    + install man/man8/sudo_root.8 in both flavours (Ubuntu specific)
    + install apport hooks
    + The ubuntu-sudo-as-admin-successful.patch was taken upstream by
      Debian however it requires a --enable-admin-flag configure flag to
      actually enable it in both flavours.
  - debian/control:
    + Mark Debian Vcs-* as XS-Debian-Vcs-*
    + update debian/control
  - debian/sudoers:
    + grant admin group sudo access
  - debian/source_sudo.py, debian/sudo-ldap.dirs, debian/sudo.dirs:
    + add usr/share/apport/package-hooks
  - debian/sudo.pam:
    + Use pam_env to read /etc/environment and /etc/default/locale
      environment files. Reading ~/.pam_environment is not permitted due to
      security reasons.
* Dropped changes:
  - debian/patches/lp927828-fix-abort-in-pam-modules-when-timestamp-valid.patch
    + Fixed upstream in 1.8.5
  - debian/patches/CVE-2012-2337.patch:
    + Fixed upstream in 1.8.4p5
  - debian/patches/pam_env_merge.patch:
    + Feature released upstream in 1.8.5
  - debian/{sudo,sudo-ldap}.{preinst,postinst,postrm}:
    + Drop Ubuntu-specific sudoers file migration code because the only
      upgrade path to quantal is from precise. All necessary sudoers file
      migration will have already been done by the time this version of the
      sudo package is installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
    void *ptr;
80
80
 
81
81
    if (size == 0)
82
 
        errorx(1, _("internal error, tried to emalloc(0)"));
 
82
        errorx2(1, _("internal error, tried to emalloc(0)"));
83
83
 
84
84
    if ((ptr = malloc(size)) == NULL)
85
 
        errorx(1, _("unable to allocate memory"));
 
85
        errorx2(1, _("unable to allocate memory"));
86
86
    return ptr;
87
87
}
88
88
 
96
96
    void *ptr;
97
97
 
98
98
    if (nmemb == 0 || size == 0)
99
 
        errorx(1, _("internal error, tried to emalloc2(0)"));
 
99
        errorx2(1, _("internal error, tried to emalloc2(0)"));
100
100
    if (nmemb > SIZE_MAX / size)
101
 
        errorx(1, _("internal error, emalloc2() overflow"));
 
101
        errorx2(1, _("internal error, emalloc2() overflow"));
102
102
 
103
103
    size *= nmemb;
104
104
    if ((ptr = malloc(size)) == NULL)
105
 
        errorx(1, _("unable to allocate memory"));
 
105
        errorx2(1, _("unable to allocate memory"));
 
106
    return ptr;
 
107
}
 
108
 
 
109
/*
 
110
 * ecalloc() allocates nmemb * size bytes and exits with an error
 
111
 * if overflow would occur or if the system malloc(3) fails.
 
112
 * On success, the allocated space is zero-filled.
 
113
 */
 
114
void *
 
115
ecalloc(size_t nmemb, size_t size)
 
116
{
 
117
    void *ptr;
 
118
 
 
119
    if (nmemb == 0 || size == 0)
 
120
        errorx2(1, _("internal error, tried to ecalloc(0)"));
 
121
    if (nmemb != 1) {
 
122
        if (nmemb > SIZE_MAX / size)
 
123
            errorx2(1, _("internal error, ecalloc() overflow"));
 
124
        size *= nmemb;
 
125
    }
 
126
    if ((ptr = malloc(size)) == NULL)
 
127
        errorx2(1, _("unable to allocate memory"));
 
128
    memset(ptr, 0, size);
106
129
    return ptr;
107
130
}
108
131
 
116
139
{
117
140
 
118
141
    if (size == 0)
119
 
        errorx(1, _("internal error, tried to erealloc(0)"));
 
142
        errorx2(1, _("internal error, tried to erealloc(0)"));
120
143
 
121
144
    ptr = ptr ? realloc(ptr, size) : malloc(size);
122
145
    if (ptr == NULL)
123
 
        errorx(1, _("unable to allocate memory"));
 
146
        errorx2(1, _("unable to allocate memory"));
124
147
    return ptr;
125
148
}
126
149
 
135
158
{
136
159
 
137
160
    if (nmemb == 0 || size == 0)
138
 
        errorx(1, _("internal error, tried to erealloc3(0)"));
 
161
        errorx2(1, _("internal error, tried to erealloc3(0)"));
139
162
    if (nmemb > SIZE_MAX / size)
140
 
        errorx(1, _("internal error, erealloc3() overflow"));
 
163
        errorx2(1, _("internal error, erealloc3() overflow"));
141
164
 
142
165
    size *= nmemb;
143
166
    ptr = ptr ? realloc(ptr, size) : malloc(size);
144
167
    if (ptr == NULL)
145
 
        errorx(1, _("unable to allocate memory"));
146
 
    return ptr;
147
 
}
 
168
        errorx2(1, _("unable to allocate memory"));
 
169
    return ptr;
 
170
}
 
171
 
 
172
#ifdef notyet
 
173
/*
 
174
 * erecalloc() realloc(3)s nmemb * msize bytes and exits with an error
 
175
 * if overflow would occur or if the system malloc(3)/realloc(3) fails.
 
176
 * On success, the new space is zero-filled.  You can call ereallocz()
 
177
 * with a NULL pointer even if the system realloc(3) does not support this.
 
178
 */
 
179
void *
 
180
erecalloc(void *ptr, size_t onmemb, size_t nmemb, size_t msize)
 
181
{
 
182
    size_t size;
 
183
 
 
184
    if (nmemb == 0 || msize == 0)
 
185
        errorx2(1, _("internal error, tried to erealloc3(0)"));
 
186
    if (nmemb > SIZE_MAX / msize)
 
187
        errorx2(1, _("internal error, erealloc3() overflow"));
 
188
 
 
189
    size = nmemb * msize;
 
190
    ptr = ptr ? realloc(ptr, size) : malloc(size);
 
191
    if (ptr == NULL)
 
192
        errorx2(1, _("unable to allocate memory"));
 
193
    if (nmemb > onmemb) {
 
194
        size = (nmemb - onmemb) * msize;
 
195
        memset((char *)ptr + (onmemb * msize), 0, size);
 
196
    }
 
197
    return ptr;
 
198
}
 
199
#endif
148
200
 
149
201
/*
150
202
 * estrdup() is like strdup(3) except that it exits with an error if
173
225
estrndup(const char *src, size_t maxlen)
174
226
{
175
227
    char *dst = NULL;
176
 
    size_t len;
 
228
    size_t len = 0;
177
229
 
178
230
    if (src != NULL) {
179
 
        len = strlen(src);
180
 
        if (len > maxlen)
181
 
            len = maxlen;
 
231
        while (maxlen != 0 && src[len] != '\0') {
 
232
            len++;
 
233
            maxlen--;
 
234
        }
182
235
        dst = (char *) emalloc(len + 1);
183
236
        (void) memcpy(dst, src, len);
184
237
        dst[len] = '\0';
200
253
    va_end(ap);
201
254
 
202
255
    if (len == -1)
203
 
        errorx(1, _("unable to allocate memory"));
 
256
        errorx2(1, _("unable to allocate memory"));
204
257
    return len;
205
258
}
206
259
 
214
267
    int len;
215
268
 
216
269
    if ((len = vasprintf(ret, format, args)) == -1)
217
 
        errorx(1, _("unable to allocate memory"));
 
270
        errorx2(1, _("unable to allocate memory"));
218
271
    return len;
219
272
}
220
273