comparison 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
comparison
equal deleted inserted replaced
17:6c59dedd06be 18:99c09ed776c1
44 44
45 in = peopen(pipe, "r", environ, &pid); 45 in = peopen(pipe, "r", environ, &pid);
46 if (in != NULL) { 46 if (in != NULL) {
47 gchar output[256]; 47 gchar output[256];
48 if (fgets(output, 255, in)) { 48 if (fgets(output, 255, in)) {
49 g_strchomp(output); 49 g_strchomp(g_strchug(output));
50 name = g_strdup(output); 50 if (strlen(output) == 0) {
51 logwrite(LOG_ALERT, "only whitespace connection name\n");
52 name = NULL;
53 } else {
54 name = g_strdup(output);
55 }
56 } else {
57 logwrite(LOG_ALERT, "nothing read from pipe %s\n", pipe);
58 name = NULL;
51 } 59 }
52 fclose(in); 60 fclose(in);
53 waitpid(pid, &status, 0); 61 waitpid(pid, &status, 0);
54 if (WEXITSTATUS(status) != EXIT_SUCCESS) { 62 if (WEXITSTATUS(status) != EXIT_SUCCESS) {
55 g_free(name); 63 g_free(name);
73 struct stat st; 81 struct stat st;
74 if (stat(conf.online_file, &st) == 0) { 82 if (stat(conf.online_file, &st) == 0) {
75 FILE *fptr = fopen(conf.online_file, "r"); 83 FILE *fptr = fopen(conf.online_file, "r");
76 if (fptr) { 84 if (fptr) {
77 char buf[256]; 85 char buf[256];
78 fgets(buf, 256, fptr); 86 if (fgets(buf, 256, fptr) == NULL) {
79 g_strchomp(buf); 87 logwrite(LOG_ALERT, "empty online file %s\n", conf.online_file);
88 fclose(fptr);
89 return NULL;
90 }
91 g_strchomp(g_strchug(buf));
80 fclose(fptr); 92 fclose(fptr);
93 if (strlen(buf) == 0) {
94 logwrite(LOG_ALERT, "only whitespace connection name in %s\n", conf.online_file);
95 return NULL;
96 }
81 return g_strdup(buf); 97 return g_strdup(buf);
82 } else { 98 } else {
83 logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno)); 99 logwrite(LOG_ALERT, "opening of %s failed: %s\n", conf.online_file, strerror(errno));
84 return NULL; 100 return NULL;
85 } 101 }