Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Apr 25, 2023
2 parents e17579e + 861298f commit cb3650e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions miniupnpd/upnppermissions.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* $Id: upnppermissions.c,v 1.20 2020/10/30 21:37:35 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2022 Thomas Bernard
* (c) 2006-2023 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */

Expand Down Expand Up @@ -152,7 +152,22 @@ get_next_token(const char * s, char ** token, int raw)
memmove(*token + i + 1, *token + i + sequence_len,
token_len - i - sequence_len);
}
*token = realloc(*token, i);
if (i == 0)
{
/* behavior of realloc(p, 0) is implementation-defined, so better set it to NULL.
* https://github.com/miniupnp/miniupnp/issues/652#issuecomment-1518922139 */
free(*token);
*token = NULL;
}
else
{
char * tmp = realloc(*token, i);
if (tmp != NULL)
*token = tmp;
else
syslog(LOG_ERR, "%s: failed to reallocate to %u bytes",
"get_next_token()", i);
}
}

/* return the beginning of the next token */
Expand All @@ -176,6 +191,9 @@ read_permission_line(struct upnpperm * perm,
int n_bits;
int i;

/* zero memory : see https://github.com/miniupnp/miniupnp/issues/652 */
memset(perm, 0, sizeof(struct upnpperm));

/* first token: (allow|deny) */
while(isspace(*p))
p++;
Expand Down

0 comments on commit cb3650e

Please sign in to comment.