mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-04 13:29:59 -05:00
fix pa_xstrndup() implementation to not access potentially uninitialized memory
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1006 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
16a275a9fd
commit
2fa08ba9aa
1 changed files with 9 additions and 10 deletions
|
|
@ -106,19 +106,18 @@ char *pa_xstrdup(const char *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pa_xstrndup(const char *s, size_t l) {
|
char *pa_xstrndup(const char *s, size_t l) {
|
||||||
|
char *e, *r;
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
else {
|
|
||||||
char *r;
|
|
||||||
size_t t = strlen(s);
|
|
||||||
|
|
||||||
if (t > l)
|
if ((e = memchr(s, 0, l)))
|
||||||
t = l;
|
return pa_xmemdup(s, e-s+1);
|
||||||
|
|
||||||
r = pa_xmemdup(s, t+1);
|
r = pa_xmalloc(l+1);
|
||||||
r[t] = 0;
|
memcpy(r, s, l);
|
||||||
|
r[l] = 0;
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pa_xfree(void *p) {
|
void pa_xfree(void *p) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue