masqmail

diff src/online.c @ 18:99c09ed776c1

fixed empty or only-whitespace connection names (Closes Debian bug #427095) stripping leading and trailing whitespace from connection names
author meillo@marmaro.de
date Thu, 06 Nov 2008 10:13:29 +0100
parents f671821d8222
children 7354c2e0eb31
line diff
     1.1 --- a/src/online.c	Thu Nov 06 09:41:35 2008 +0100
     1.2 +++ b/src/online.c	Thu Nov 06 10:13:29 2008 +0100
     1.3 @@ -46,8 +46,16 @@
     1.4  	if (in != NULL) {
     1.5  		gchar output[256];
     1.6  		if (fgets(output, 255, in)) {
     1.7 -			g_strchomp(output);
     1.8 -			name = g_strdup(output);
     1.9 +			g_strchomp(g_strchug(output));
    1.10 +			if (strlen(output) == 0) {
    1.11 +				logwrite(LOG_ALERT, "only whitespace connection name\n");
    1.12 +				name = NULL;
    1.13 +			} else {
    1.14 +				name = g_strdup(output);
    1.15 +			}
    1.16 +		} else {
    1.17 +			logwrite(LOG_ALERT, "nothing read from pipe %s\n", pipe);
    1.18 +			name = NULL;
    1.19  		}
    1.20  		fclose(in);
    1.21  		waitpid(pid, &status, 0);
    1.22 @@ -75,9 +83,17 @@
    1.23  					FILE *fptr = fopen(conf.online_file, "r");
    1.24  					if (fptr) {
    1.25  						char buf[256];
    1.26 -						fgets(buf, 256, fptr);
    1.27 -						g_strchomp(buf);
    1.28 +						if (fgets(buf, 256, fptr) == NULL) {
    1.29 +							logwrite(LOG_ALERT, "empty online file %s\n", conf.online_file);
    1.30 +							fclose(fptr);
    1.31 +							return NULL;
    1.32 +						}
    1.33 +						g_strchomp(g_strchug(buf));
    1.34  						fclose(fptr);
    1.35 +						if (strlen(buf) == 0) {
    1.36 +							logwrite(LOG_ALERT, "only whitespace connection name in %s\n", conf.online_file);
    1.37 +							return NULL;
    1.38 +						}
    1.39  						return g_strdup(buf);
    1.40  					} else {
    1.41  						logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));