Skip to content

Commit a202a87

Browse files
committed
Fix possible illegal memory access
Coverity says: "CID 47629 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING)11. buffer_size_warning: Calling strncpy with a maximum size argument of 255 bytes on destination array config->configfile of size 255 bytes might leave the destination string unterminated." Instead of strncpy, the code now uses safe_strdup. This also lifts the 255 characters limit. While file names are indeed limitted to 255 chars on some file systems, path length is typically unlimitted.
1 parent d9570b7 commit a202a87

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/commandline.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void parse_commandline(int argc, char **argv) {
106106

107107
case 'c':
108108
if (optarg) {
109-
strncpy(config->configfile, optarg, sizeof(config->configfile));
109+
config->configfile = safe_strdup(optarg);
110110
}
111111
break;
112112

src/conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void
170170
config_init(void)
171171
{
172172
debug(LOG_DEBUG, "Setting default config parameters");
173-
strncpy(config.configfile, DEFAULT_CONFIGFILE, sizeof(config.configfile));
173+
config.configfile = safe_strdup(DEFAULT_CONFIGFILE);
174174
config.htmlmsgfile = safe_strdup(DEFAULT_HTMLMSGFILE);
175175
config.debuglevel = DEFAULT_DEBUGLEVEL;
176176
config.httpdmaxconn = DEFAULT_HTTPDMAXCONN;

src/conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef struct _trusted_mac_t {
147147
* Configuration structure
148148
*/
149149
typedef struct {
150-
char configfile[255]; /**< @brief name of the config file */
150+
char *configfile; /**< @brief name of the config file */
151151
char *htmlmsgfile; /**< @brief name of the HTML file used for messages */
152152
char *wdctl_sock; /**< @brief wdctl path to socket */
153153
char *internal_sock; /**< @brief internal path to socket */

0 commit comments

Comments
 (0)