From 2a53bb0e24c81e7d9bc914da0f6c144ddb9bfca8 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Sat, 22 Dec 2001 15:22:59 +0000 Subject: [PATCH] Some last minute tweaks - type fixes from Stefan and win32 temp files from Timo. --- g10/ChangeLog | 11 +++++++++++ g10/exec.c | 9 ++++++++- g10/mkdtemp.c | 23 ++++++++++++++++------- g10/photoid.c | 8 +++++--- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 890ad3731..2691716e3 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,14 @@ +2001-12-22 David Shaw + + * mkdtemp.c (mkdtemp): catch the empty ("") string case in case + someone repurposes mkdtemp at some point. + + * photoid.c (generate_photo_id, show_photo): some type changes + from Stefan Bellon. + + * exec.c (make_tempdir): handle Win32 systems, suggested by Timo + Schulz. + 2001-12-22 Werner Koch * encode.c (encode_simple, encode_crypt): i18n 2 strings. diff --git a/g10/exec.c b/g10/exec.c index 1685cb6cb..652ed456e 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -56,6 +56,9 @@ static int make_tempdir(struct exec_info *info) { #ifdef __riscos__ tmp=""; +#elsif HAVE_DOSISH_SYSTEM + tmp=m_alloc(1024); + GetTempPath(1023,tmp); #else tmp="/tmp"; #endif @@ -67,6 +70,10 @@ static int make_tempdir(struct exec_info *info) sprintf(info->tempdir,"%s" DIRSEP_S "gpg-XXXXXX",tmp); +#ifdef HAVE_DOSISH_SYSTEM + m_free(tmp); +#endif + if(mkdtemp(info->tempdir)==NULL) log_error(_("%s: can't create directory: %s\n"), info->tempdir,strerror(errno)); @@ -189,7 +196,7 @@ static int expand_args(struct exec_info *info,const char *args_in) /* The rules are: if there are no args, then it's a fork/exec/pipe. If there are args, but no tempfiles, then it's a fork/exec/pipe via - bash -c. If there are tempfiles, then it's a system. */ + shell -c. If there are tempfiles, then it's a system. */ int exec_write(struct exec_info **info,const char *program, const char *args_in,int writeonly,int binary) diff --git a/g10/mkdtemp.c b/g10/mkdtemp.c index 6a159c02b..625ab148f 100644 --- a/g10/mkdtemp.c +++ b/g10/mkdtemp.c @@ -13,14 +13,21 @@ char *mkdtemp(char *template) { - int attempts,index,count=0; + int attempts,idx,count=0; byte *ch; - index=strlen(template); - ch=&template[index-1]; + idx=strlen(template); + + if(idx==0) + { + errno=EINVAL; + return NULL; + } + + ch=&template[idx-1]; /* Walk backwards to count all the Xes */ - while(*ch=='X' && count1) { - sprintf(marker,"%02X",randombits[index++]); + sprintf(marker,"%02X",randombits[idx++]); marker+=2; remaining-=2; } @@ -57,7 +66,7 @@ char *mkdtemp(char *template) /* Any leftover Xes? get_random_bits rounds up to full bytes, so this is safe. */ if(remaining>0) - sprintf(marker,"%X",randombits[index]&0xF); + sprintf(marker,"%X",randombits[idx]&0xF); m_free(randombits); diff --git a/g10/photoid.c b/g10/photoid.c index 4cc96de61..bf67c2a66 100644 --- a/g10/photoid.c +++ b/g10/photoid.c @@ -46,9 +46,10 @@ PKT_user_id *generate_photo_id(PKT_public_key *pk) { PKT_user_id *uid; - int error=1,i,len; + int error=1,i; + unsigned int len; char *filename=NULL; - unsigned char *photo=NULL; + byte *photo=NULL; byte header[16]; IOBUF file; @@ -194,7 +195,8 @@ void show_photo(const struct user_attribute *attr,PKT_public_key *pk) case 'f': /* fingerprint */ { byte array[MAX_FINGERPRINT_LEN]; - int len,i; + size_t len; + int i; fingerprint_from_pk(pk,array,&len);