From 2e50584f9b558d03d11d209fcdd2ed8e237bb551 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 10 Oct 2018 12:24:41 -0400 Subject: [PATCH] dos33fs: fix some compiler warnings --- dos33fs-utils/dos33.c | 110 ++++++++++++++++++++++++++++++++------ dos33fs-utils/mkdos33fs.c | 4 +- 2 files changed, 95 insertions(+), 19 deletions(-) diff --git a/dos33fs-utils/dos33.c b/dos33fs-utils/dos33.c index b730a6ca..c972b4ec 100644 --- a/dos33fs-utils/dos33.c +++ b/dos33fs-utils/dos33.c @@ -219,10 +219,8 @@ static int dos33_print_file_info(int fd,int catalog_tsf) { printf("%.3i ",sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE+FILE_SIZE_L)]+ (sector_buffer[CATALOG_FILE_LIST+(catalog_file*CATALOG_ENTRY_SIZE+FILE_SIZE_H)]<<8)); - strncpy(temp_string, - dos33_filename_to_ascii(temp_string,sector_buffer+(CATALOG_FILE_LIST+ - (catalog_file*CATALOG_ENTRY_SIZE+FILE_NAME)),30), - BUFSIZ); + dos33_filename_to_ascii(temp_string,sector_buffer+(CATALOG_FILE_LIST+ + (catalog_file*CATALOG_ENTRY_SIZE+FILE_NAME)),30); for(i=0;ioptind) { if (debug) printf("Using %s for filename\n", local_filename); - strncpy(local_filename,argv[optind],BUFSIZ); + strncpy(local_filename,argv[optind],BUFSIZ-1); } else { if (debug) printf("Using %s for filename\n", apple_filename); - strncpy(local_filename,apple_filename,30); + strncpy(local_filename,apple_filename,31); } if (debug) printf("\tOutput filename: %s\n",local_filename); @@ -1712,7 +1708,87 @@ int main(int argc, char **argv) { goto exit_and_close; } - strncpy(local_filename,argv[optind],BUFSIZ); + strncpy(local_filename,argv[optind],BUFSIZ-1); + optind++; + + if (debug) printf("\tLocal filename: %s\n",local_filename); + + if (argc>optind) { + /* apple filename specified */ + truncate_filename(apple_filename,argv[optind]); + } + else { + /* If no filename specified for apple name */ + /* Then use the input name. Note, we strip */ + /* everything up to the last slash so useless */ + /* path info isn't used */ + + temp=local_filename+(strlen(local_filename)-1); + + while(temp!=local_filename) { + temp--; + if (*temp == '/') { + temp++; + break; + } + } + + truncate_filename(apple_filename,temp); + } + + if (debug) printf("\tApple filename: %s\n",apple_filename); + + catalog_entry=dos33_check_file_exists(dos_fd,apple_filename, + FILE_NORMAL); + + if (catalog_entry>=0) { + fprintf(stderr,"Warning! %s exists!\n",apple_filename); + if (!always_yes) { + printf("Over-write (y/n)?"); + result_string=fgets(temp_string,BUFSIZ,stdin); + if ((result_string==NULL) || (temp_string[0]!='y')) { + printf("Exiting early...\n"); + goto exit_and_close; + } + } + fprintf(stderr,"Deleting previous version...\n"); + dos33_delete_file(dos_fd,catalog_entry); + } + if (command==COMMAND_SAVE) { + dos33_add_file(dos_fd,type, + ADD_RAW, address, length, + local_filename,apple_filename); + } + else { + dos33_add_file(dos_fd,type, + ADD_BINARY, address, length, + local_filename,apple_filename); + } + break; + + + case COMMAND_RAW_WRITE: + + if (debug) printf("\ttype=%c\n",type); + + if (argc==optind) { + fprintf(stderr,"Error! Need file_name\n"); + + if (command==COMMAND_BSAVE) { + fprintf(stderr,"%s %s BSAVE " + "file_name apple_filename\n\n", + argv[0],image); + + } + else { + fprintf(stderr,"%s %s SAVE type " + "file_name apple_filename\n\n", + argv[0],image); + } + goto exit_and_close; + } + + strncpy(local_filename,argv[optind],BUFSIZ-1); optind++; if (debug) printf("\tLocal filename: %s\n",local_filename); diff --git a/dos33fs-utils/mkdos33fs.c b/dos33fs-utils/mkdos33fs.c index 86035f33..432b809b 100644 --- a/dos33fs-utils/mkdos33fs.c +++ b/dos33fs-utils/mkdos33fs.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) { break; case 'd': copy_dos=1; - strncpy(dos_src,optarg,BUFSIZ); + strncpy(dos_src,optarg,BUFSIZ-1); break; case 'f': if (strlen(optarg)>30) { @@ -79,7 +79,7 @@ int main(int argc, char **argv) { goto end_of_program; } - strncpy(device,argv[optind],BUFSIZ); + strncpy(device,argv[optind],BUFSIZ-1); /* Sanity check values */