diff --git a/client/client_shared.c b/client/client_shared.c index d5d3725629..2788b7ce51 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -974,7 +974,11 @@ int client_id_generate(struct mosq_config *cfg, const char *id_base) int client_connect(struct mosquitto *mosq, struct mosq_config *cfg) { +#ifndef WIN32 + char *err; +#else char err[1024]; +#endif int rc; int port; @@ -1008,7 +1012,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg) if(!cfg->quiet){ if(rc == MOSQ_ERR_ERRNO){ #ifndef WIN32 - strerror_r(errno, err, 1024); + err = strerror(errno); #else FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errno, 0, (LPTSTR)&err, 1024, NULL); #endif diff --git a/src/mosquitto.c b/src/mosquitto.c index eb90260ca7..768d5c102e 100644 --- a/src/mosquitto.c +++ b/src/mosquitto.c @@ -91,7 +91,7 @@ int drop_privileges(struct mosquitto__config *config, bool temporary) { #if !defined(__CYGWIN__) && !defined(WIN32) struct passwd *pwd; - char err[256]; + char *err; int rc; const char *snap = getenv("SNAP_NAME"); @@ -108,7 +108,7 @@ int drop_privileges(struct mosquitto__config *config, bool temporary) return 1; } if(initgroups(config->user, pwd->pw_gid) == -1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error setting groups whilst dropping privileges: %s.", err); return 1; } @@ -118,7 +118,7 @@ int drop_privileges(struct mosquitto__config *config, bool temporary) rc = setgid(pwd->pw_gid); } if(rc == -1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error setting gid whilst dropping privileges: %s.", err); return 1; } @@ -128,7 +128,7 @@ int drop_privileges(struct mosquitto__config *config, bool temporary) rc = setuid(pwd->pw_uid); } if(rc == -1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error setting uid whilst dropping privileges: %s.", err); return 1; } @@ -144,19 +144,19 @@ int drop_privileges(struct mosquitto__config *config, bool temporary) int restore_privileges(void) { #if !defined(__CYGWIN__) && !defined(WIN32) - char err[256]; + char *err; int rc; if(getuid() == 0){ rc = setegid(0); if(rc == -1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error setting gid whilst restoring privileges: %s.", err); return 1; } rc = seteuid(0); if(rc == -1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error setting uid whilst restoring privileges: %s.", err); return 1; } @@ -169,12 +169,12 @@ int restore_privileges(void) void mosquitto__daemonise(void) { #ifndef WIN32 - char err[256]; + char *err; pid_t pid; pid = fork(); if(pid < 0){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error in fork: %s", err); exit(1); } @@ -182,7 +182,7 @@ void mosquitto__daemonise(void) exit(0); } if(setsid() < 0){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error in setsid: %s", err); exit(1); } diff --git a/src/net.c b/src/net.c index 780a5f0bc0..08f2b824fa 100644 --- a/src/net.c +++ b/src/net.c @@ -81,18 +81,16 @@ void net__broker_cleanup(void) static void net__print_error(int log, const char *format_str) { -#ifdef WIN32 char *buf; +#ifdef WIN32 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, WSAGetLastError(), LANG_NEUTRAL, &buf, 0, NULL); log__printf(NULL, log, format_str, buf); LocalFree(buf); #else - char buf[256]; - - strerror_r(errno, buf, 256); + buf = strerror(errno); log__printf(NULL, log, format_str, buf); #endif } diff --git a/src/persist.c b/src/persist.c index 7a93f98427..b83327c340 100644 --- a/src/persist.c +++ b/src/persist.c @@ -356,7 +356,7 @@ int persist__backup(struct mosquitto_db *db, bool shutdown) uint32_t i32temp; uint16_t i16temp; uint8_t i8temp; - char err[256]; + char *err; char *outfile = NULL; int len; @@ -477,7 +477,7 @@ int persist__backup(struct mosquitto_db *db, bool shutdown) return rc; error: mosquitto__free(outfile); - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); if(db_fptr) fclose(db_fptr); return 1; @@ -596,7 +596,7 @@ static int persist__client_msg_chunk_restore(struct mosquitto_db *db, FILE *db_f uint8_t qos, retain, direction, state, dup; char *client_id = NULL; int rc; - char err[256]; + char *err; read_e(db_fptr, &i16temp, sizeof(uint16_t)); slen = ntohs(i16temp); @@ -631,7 +631,7 @@ static int persist__client_msg_chunk_restore(struct mosquitto_db *db, FILE *db_f return rc; error: - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); fclose(db_fptr); mosquitto__free(client_id); @@ -650,7 +650,7 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp int rc = 0; struct mosquitto_msg_store *stored = NULL; struct mosquitto_msg_store_load *load; - char err[256]; + char *err; payload.ptr = NULL; @@ -734,7 +734,7 @@ static int persist__msg_store_chunk_restore(struct mosquitto_db *db, FILE *db_fp return rc; } error: - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); fclose(db_fptr); mosquitto__free(source_id); @@ -747,10 +747,10 @@ static int persist__retain_chunk_restore(struct mosquitto_db *db, FILE *db_fptr) { dbid_t i64temp, store_id; struct mosquitto_msg_store_load *load; - char err[256]; + char *err; if(fread(&i64temp, sizeof(dbid_t), 1, db_fptr) != 1){ - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); fclose(db_fptr); return 1; @@ -773,7 +773,7 @@ static int persist__sub_chunk_restore(struct mosquitto_db *db, FILE *db_fptr) char *client_id; char *topic; int rc = 0; - char err[256]; + char *err; read_e(db_fptr, &i16temp, sizeof(uint16_t)); slen = ntohs(i16temp); @@ -807,7 +807,7 @@ static int persist__sub_chunk_restore(struct mosquitto_db *db, FILE *db_fptr) return rc; error: - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); fclose(db_fptr); return 1; @@ -824,7 +824,7 @@ int persist__restore(struct mosquitto_db *db) uint16_t i16temp, chunk; uint8_t i8temp; ssize_t rlen; - char err[256]; + char *err; struct mosquitto_msg_store_load *load, *load_tmp; assert(db); @@ -919,7 +919,7 @@ int persist__restore(struct mosquitto_db *db) } return rc; error: - strerror_r(errno, err, 256); + err = strerror(errno); log__printf(NULL, MOSQ_LOG_ERR, "Error: %s.", err); if(fptr) fclose(fptr); return 1;