1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix a potential read of uninitialized memory through a pointer

src/lib/libast/misc/magic.c:
- Use strncpy instead of memcpy to avoid reading past the null
  terminator of the string pointed to by p.
This commit is contained in:
Lev Kujawski 2021-02-11 20:04:11 -07:00 committed by Martijn Dekker
parent 3224b79083
commit a9e7012dfd

View file

@ -687,8 +687,8 @@ ckmagic(register Magic_t* mp, const char* file, char* buf, char* end, struct sta
c = mp->fbsz; c = mp->fbsz;
if (c >= sizeof(mp->nbuf)) if (c >= sizeof(mp->nbuf))
c = sizeof(mp->nbuf) - 1; c = sizeof(mp->nbuf) - 1;
p = (char*)memcpy(mp->nbuf, p, c); p = strncpy(mp->nbuf, p, c);
p[c] = 0; p[c] = '\0';
ccmapstr(mp->x2n, p, c); ccmapstr(mp->x2n, p, c);
if ((c = regexec(ep->value.sub, p, elementsof(matches), matches, 0)) || (c = regsubexec(ep->value.sub, p, elementsof(matches), matches))) if ((c = regexec(ep->value.sub, p, elementsof(matches), matches, 0)) || (c = regsubexec(ep->value.sub, p, elementsof(matches), matches)))
{ {