Giter VIP home page Giter VIP logo

Comments (7)

ryancaicse avatar ryancaicse commented on August 13, 2024

File fp is not closed at Line 186 and 193

fp = fopen(file, "rb");
if(fp != NULL)
{
(void) fseek(fp, 0, SEEK_END);
*size = ftell(fp);
rewind(fp);
if(*size < sizeof(Elf32_Ehdr))
{
fprintf(stderr, "Error, invalid file size\n");
break;
}
data = (unsigned char *) malloc(*size);
if(data == NULL)
{
fprintf(stderr, "Error, could not allocate memory for ELF\n");
break;
}
(void) fread(data, 1, *size, fp);
fclose(fp);

from pspsdk.

ryancaicse avatar ryancaicse commented on August 13, 2024

File source is not closed at Line 365 and 370

pspsdk/tools/bin2o.c

Lines 347 to 372 in d019dbc

if (!(source = fopen(f_source, "rb"))) {
printf("Error opening %s for reading.\n", f_source);
return 1;
}
fseek(source, 0, SEEK_END);
fd_size = ftell(source);
fseek(source, start, SEEK_SET);
if (fd_size < end)
end = fd_size;
if (end < (size - start))
size = end - start;
buffer = malloc(size);
if (buffer == NULL) {
printf("Failed to allocate memory.\n");
return 1;
}
if (fread(buffer, 1, size, source) != size) {
printf("Failed to read file.\n");
return 1;
}
fclose(source);

from pspsdk.

ryancaicse avatar ryancaicse commented on August 13, 2024

Files infile and outfile are not closed at the erroneous returns

pspsdk/tools/unpack-pbp.c

Lines 83 to 156 in d019dbc

infile = fopen(argv[1], "rb");
if (infile == NULL) {
printf("ERROR: Could not open the input file. (%s)\n", argv[1]);
return -1;
}
// Get the size of the PBP
fseek(infile, 0, SEEK_END);
total_size = ftell(infile);
fseek(infile, 0, SEEK_SET);
if (total_size < 0) {
printf("ERROR: Could not get the input file size.\n");
return -1;
}
// Read in the header
if (fread(&header, sizeof(HEADER), 1, infile) < 0) {
printf("ERROR: Could not read the input file header.\n");
return -1;
}
// Check the signature
for (loop0 = 0; loop0 < sizeof(correct_sig); loop0++) {
if (header.signature[loop0] != correct_sig[loop0]) {
printf("ERROR: Input file is not a PBP file.\n");
return -1;
}
}
#ifdef WORDS_BIGENDIAN
// Swap the bytes of the offsets for big-endian machines
for (loop0 = 0; loop0 < 8; loop0++) {
header.offset[loop0] = swap_int(header.offset[loop0]);
}
#endif
// For each file in the PBP
for (loop0 = 0; loop0 < 8; loop0++) {
void *buffer;
int size;
// Get the size of this file
if (loop0 == 7) {
size = total_size - header.offset[loop0];
} else {
size = header.offset[loop0 + 1] - header.offset[loop0];
}
// Print out the file details
printf("[%d] %10d bytes | %s\n", loop0, size, filename[loop0]);
// Skip the file if empty
if (!size) continue;
// Seek to the proper position in the file
if (fseek(infile, header.offset[loop0], SEEK_SET) != 0) {
printf("ERROR: Could not seek in the input file.\n");
return -1;
}
// Open the output file
outfile = fopen(filename[loop0], "wb");
if (outfile == NULL) {
printf("ERROR: Could not open the output file. (%s)\n", filename[loop0]);
return -1;
}
// Create the read buffer
buffer = malloc(maxbuffer);
if (buffer == NULL) {
printf("ERROR: Could not allocate the section data buffer. (%d)\n", maxbuffer);
return -1;

from pspsdk.

ryancaicse avatar ryancaicse commented on August 13, 2024

File source is not closed at Line 43 and 48

pspsdk/tools/bin2s.c

Lines 30 to 50 in d019dbc

if((source=fopen( argv[1], "rb")) == NULL) {
printf("Error opening %s for reading.\n",argv[1]);
return 1;
}
fseek(source,0,SEEK_END);
fd_size = ftell(source);
fseek(source,0,SEEK_SET);
buffer = malloc(fd_size);
if(buffer == NULL) {
printf("Failed to allocate memory.\n");
return 1;
}
if(fread(buffer,1,fd_size,source) != fd_size) {
printf("Failed to read file.\n");
return 1;
}
fclose(source);

from pspsdk.

mrneo240 avatar mrneo240 commented on August 13, 2024

most modern sane toolchains flush and close file handles on clean exit or return from main.

from pspsdk.

wally4000 avatar wally4000 commented on August 13, 2024

Wouldn't it be worth fixing these to just be compliant anyway? Considering these tools are compiled for the host

Could you please submit a pull request @ryancaicse as it will gather more interest.

from pspsdk.

ryancaicse avatar ryancaicse commented on August 13, 2024

OK, please check

from pspsdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.