Skip to content

Commit

Permalink
Fixed the indexing of filename_t past its end in DD_SetConfigFile.
Browse files Browse the repository at this point in the history
Also, fixed dangerous misplaced parentheses in the same function.

Danij: I am officially worried about the usage of FILENAME_T_MAXLEN.
You should check each instance where it's used and check if, in fact, 
you should use FILENAME_T_LASTINDEX.
  • Loading branch information
skyjake committed Jun 28, 2009
1 parent ae22a1f commit 4cc723c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion doomsday/engine/api/dd_types.h
Expand Up @@ -119,9 +119,11 @@ typedef unsigned short thid_t;
typedef unsigned char byte;
typedef double timespan_t;

#define FILENAME_T_MAXLEN (256)
#define FILENAME_T_MAXLEN 256
typedef char filename_t[FILENAME_T_MAXLEN];

#define FILENAME_T_LASTINDEX 255

typedef struct directory_s {
int drive;
filename_t path;
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -263,16 +263,16 @@ int DD_AddAutoData(boolean loadFiles)
void DD_SetConfigFile(const char* file)
{
strncpy(configFileName, file, FILENAME_T_MAXLEN);
configFileName[FILENAME_T_MAXLEN] = '\0';
configFileName[FILENAME_T_LASTINDEX] = '\0';

Dir_FixSlashes(configFileName, FILENAME_T_MAXLEN);

strncpy(bindingsConfigFileName, configFileName, FILENAME_T_MAXLEN);
bindingsConfigFileName[FILENAME_T_MAXLEN] = '\0';
bindingsConfigFileName[FILENAME_T_LASTINDEX] = '\0';

strncpy(bindingsConfigFileName + strlen(bindingsConfigFileName) - 4,
"-bindings.cfg", FILENAME_T_MAXLEN - strlen(bindingsConfigFileName - 4));
bindingsConfigFileName[FILENAME_T_MAXLEN] = '\0';
"-bindings.cfg", FILENAME_T_MAXLEN - strlen(bindingsConfigFileName) - 4);
bindingsConfigFileName[FILENAME_T_LASTINDEX] = '\0';
}

/**
Expand Down

0 comments on commit 4cc723c

Please sign in to comment.