mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-09-22 10:43:39 -04:00
quote_for_pmake: fix counter underrun resulting in segfault
while (nbs--) { ... } ends with nbs == -1. Rather than a minimal fix, introduce mempset() to make these kinds of errors less likely in the future. Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392815 Reported-by: <13579and24680@gmail.com> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
10
asm/nasm.c
10
asm/nasm.c
@@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------- *
|
||||
*
|
||||
* Copyright 1996-2020 The NASM Authors - All Rights Reserved
|
||||
* Copyright 1996-2022 The NASM Authors - All Rights Reserved
|
||||
* See the file AUTHORS included with the NASM distribution for
|
||||
* the specific copyright holders.
|
||||
*
|
||||
@@ -817,7 +817,6 @@ static char *quote_for_pmake(const char *str)
|
||||
}
|
||||
|
||||
/* Convert N backslashes at the end of filename to 2N backslashes */
|
||||
if (nbs)
|
||||
n += nbs;
|
||||
|
||||
os = q = nasm_malloc(n);
|
||||
@@ -827,10 +826,10 @@ static char *quote_for_pmake(const char *str)
|
||||
switch (*p) {
|
||||
case ' ':
|
||||
case '\t':
|
||||
while (nbs--)
|
||||
*q++ = '\\';
|
||||
q = mempset(q, '\\', nbs);
|
||||
*q++ = '\\';
|
||||
*q++ = *p;
|
||||
nbs = 0;
|
||||
break;
|
||||
case '$':
|
||||
*q++ = *p;
|
||||
@@ -852,9 +851,8 @@ static char *quote_for_pmake(const char *str)
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (nbs--)
|
||||
*q++ = '\\';
|
||||
|
||||
q = mempset(q, '\\', nbs);
|
||||
*q = '\0';
|
||||
|
||||
return os;
|
||||
|
@@ -200,6 +200,7 @@ AC_CHECK_FUNCS(strrchrnul)
|
||||
AC_CHECK_FUNCS(iscntrl)
|
||||
AC_CHECK_FUNCS(isascii)
|
||||
AC_CHECK_FUNCS(mempcpy)
|
||||
AC_CHECK_FUNCS(mempset)
|
||||
|
||||
AC_CHECK_FUNCS(getuid)
|
||||
AC_CHECK_FUNCS(getgid)
|
||||
|
@@ -252,6 +252,13 @@ static inline void *mempcpy(void *dst, const void *src, size_t n)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMPSET
|
||||
static inline void *mempset(void *dst, int c, size_t n)
|
||||
{
|
||||
return (char *)memset(dst, c, n) + n;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hack to support external-linkage inline functions
|
||||
*/
|
||||
|
Reference in New Issue
Block a user