mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -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 *e, *r;
|
||||
|
||||
if (!s)
|
||||
return NULL;
|
||||
else {
|
||||
char *r;
|
||||
size_t t = strlen(s);
|
||||
|
||||
if (t > l)
|
||||
t = l;
|
||||
if ((e = memchr(s, 0, l)))
|
||||
return pa_xmemdup(s, e-s+1);
|
||||
|
||||
r = pa_xmemdup(s, t+1);
|
||||
r[t] = 0;
|
||||
return r;
|
||||
}
|
||||
r = pa_xmalloc(l+1);
|
||||
memcpy(r, s, l);
|
||||
r[l] = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
void pa_xfree(void *p) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue