Skip to content

Commit

Permalink
Fix champ mem alloc file buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JarrettSJohnson committed May 11, 2024
1 parent 1e9d81d commit 5f0106a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions contrib/champ/os_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ void *OSMemoryMalloc(unsigned int size,const char *file,int line,int type)
rec=(DebugRec*)malloc(sizeof(DebugRec)+size);
if(!rec)
return(NULL);
strcpy(rec->file,file);

int len = strlen(file);
int max_size = sizeof(rec->file) - 1;
if (len > max_size) {
strcpy(rec->file, file + len - max_size);
} else {
strcpy(rec->file, file);
}
rec->file[max_size - 1] = '\0';
rec->line=line;
rec->size=size;
rec->type=type;
Expand All @@ -196,7 +204,15 @@ void *OSMemoryCalloc(unsigned int count,unsigned int size,const char *file,int l
rec=(DebugRec*)calloc(1,sizeof(DebugRec)+size);
if(!rec)
return(NULL);
strcpy(rec->file,file);

int len = strlen(file);
int max_size = sizeof(rec->file) - 1;
if (len > max_size) {
strcpy(rec->file, file + len - max_size);
} else {
strcpy(rec->file, file);
}
rec->file[max_size - 1] = '\0';
rec->line=line;
rec->size=size;
rec->type=type;
Expand Down

0 comments on commit 5f0106a

Please sign in to comment.