From f77cb9933d71a75b4764173eafc9dd972e190853 Mon Sep 17 00:00:00 2001 From: Keith Marshall Date: Fri, 11 Jan 2019 20:03:49 +0000 Subject: [PATCH] Fix a mkstemp() file name generator defect. --- mingwrt/ChangeLog | 8 ++++++++ mingwrt/mingwex/cryptnam.c | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/mingwrt/ChangeLog b/mingwrt/ChangeLog index 4261278..31d9509 100644 --- a/mingwrt/ChangeLog +++ b/mingwrt/ChangeLog @@ -1,5 +1,13 @@ 2019-01-11 Keith Marshall + Fix a mkstemp() file name generator defect. + + * mingwex/cryptnam.c (crypto_random_filename_char): Revert 2018-09-06 + change; argument type must be unsigned char *, to avoid math errors. + (__mingw_crypto_tmpname): Use explicit casts to resolve type conflicts. + +2019-01-11 Keith Marshall + Fix a typedef omission. * include/stdio.h: Adjust comment formatting. diff --git a/mingwrt/mingwex/cryptnam.c b/mingwrt/mingwex/cryptnam.c index 4b6eac4..7758518 100644 --- a/mingwrt/mingwex/cryptnam.c +++ b/mingwrt/mingwex/cryptnam.c @@ -10,7 +10,7 @@ * $Id$ * * Written by Keith Marshall - * Copyright (C) 2013, 2014, 2018, MinGW.org Project. + * Copyright (C) 2013, 2014, 2018, 2019, MinGW.org Project. * * * Permission is hereby granted, free of charge, to any person obtaining a @@ -94,7 +94,8 @@ CRYPTO_INLINE void *crypto_randomize( void *buf, size_t buflen ) return NULL; } -CRYPTO_INLINE char *crypto_random_filename_char( char *caret ) +CRYPTO_INLINE +unsigned char *crypto_random_filename_char( unsigned char *caret ) { /* Helper to generate a random sequence of characters, suitable for * use in file names; although there are other valid possibilities, we @@ -155,12 +156,12 @@ char *__mingw_crypto_tmpname( char *template ) * We begin by locating the position, within the given template, * where the string of six replaceable 'XXXXXX's should begin. */ - char *tail = template + strlen( template ) - 6; + unsigned char *tail = (unsigned char *)(template) + strlen( template ) - 6; /* Provided this appears sane -- i.e. it at least doesn't place the * six character "tail" before the start of the template itself... */ - if( tail >= template ) + if( (char *)(tail) >= template ) { /* ...then, walk over each of the six bytes of the "tail", until * we reach the NUL terminator... -- 2.11.0