Skip to content

Commit b184073

Browse files
committed
Avoid OOB reads in create_name_with_username()
`accel_uname_id` and `zend_system_id` are MD5 buffers which are not NUL terminated. Thus, we must not pass them to `snprintf()`. Closes GH-6968.
1 parent 96bf925 commit b184073

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ext/opcache/shared_alloc_win32.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,19 @@ static void zend_win_error_message(int type, char *msg, int err)
7070

7171
static char *create_name_with_username(char *name)
7272
{
73-
static char newname[MAXPATHLEN + 32 + 4 + 1 + 32 + 21];
74-
snprintf(newname, sizeof(newname) - 1, "%s@%.32s@%.20s@%.32s", name, accel_uname_id, sapi_module.name, accel_system_id);
73+
static char newname[MAXPATHLEN + 1 + 32 + 1 + 20 + 1 + 32 + 1];
74+
char *p = newname;
75+
p += strlcpy(newname, name, MAXPATHLEN + 1);
76+
*(p++) = '@';
77+
memcpy(p, accel_uname_id, 32);
78+
p += 32;
79+
*(p++) = '@';
80+
p += strlcpy(p, sapi_module.name, 21);
81+
*(p++) = '@';
82+
memcpy(p, accel_system_id, 32);
83+
p += 32;
84+
*(p++) = '\0';
85+
ZEND_ASSERT(p - newname <= sizeof(newname));
7586

7687
return newname;
7788
}

0 commit comments

Comments
 (0)