aboutsummaryrefslogtreecommitdiff
path: root/src/topology
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-12 12:11:53 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-12 12:11:53 +0100
commit9428ea3004c5b90949cfb46174a2bcd7e76ac816 (patch)
treeff11f95f58f29db725d2dd95da8c588ef28985f7 /src/topology
parent2dd837124cd405982b0fcfa0057a688e2f34ab9d (diff)
downloadgnunet-9428ea3004c5b90949cfb46174a2bcd7e76ac816.tar.gz
gnunet-9428ea3004c5b90949cfb46174a2bcd7e76ac816.zip
fix #5242 topology.txt write issue
Diffstat (limited to 'src/topology')
-rw-r--r--src/topology/friends.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/topology/friends.c b/src/topology/friends.c
index 65f2700bb..cdfedbc81 100644
--- a/src/topology/friends.c
+++ b/src/topology/friends.c
@@ -46,6 +46,7 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
46 size_t start; 46 size_t start;
47 struct GNUNET_PeerIdentity pid; 47 struct GNUNET_PeerIdentity pid;
48 uint64_t fsize; 48 uint64_t fsize;
49 ssize_t ssize;
49 50
50 if (GNUNET_OK != 51 if (GNUNET_OK !=
51 GNUNET_CONFIGURATION_get_value_filename (cfg, 52 GNUNET_CONFIGURATION_get_value_filename (cfg,
@@ -57,13 +58,24 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
57 "topology", "FRIENDS"); 58 "topology", "FRIENDS");
58 return GNUNET_SYSERR; 59 return GNUNET_SYSERR;
59 } 60 }
60 if ( (GNUNET_OK != GNUNET_DISK_file_test (fn)) && 61 if (GNUNET_SYSERR ==
61 (GNUNET_OK != GNUNET_DISK_fn_write (fn, 62 GNUNET_DISK_directory_create_for_file (fn))
62 NULL, 63 {
63 0, 64 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
64 GNUNET_DISK_PERM_USER_READ | 65 "mkdir",
65 GNUNET_DISK_PERM_USER_WRITE | 66 fn);
66 GNUNET_DISK_OPEN_CREATE)) ) 67 GNUNET_free (fn);
68 return GNUNET_SYSERR;
69 }
70 if ( (GNUNET_OK !=
71 GNUNET_DISK_file_test (fn)) &&
72 (GNUNET_OK !=
73 GNUNET_DISK_fn_write (fn,
74 NULL,
75 0,
76 GNUNET_DISK_PERM_USER_READ |
77 GNUNET_DISK_PERM_USER_WRITE |
78 GNUNET_DISK_OPEN_CREATE)) )
67 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 79 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
68 "write", 80 "write",
69 fn); 81 fn);
@@ -84,9 +96,15 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
84 GNUNET_free (fn); 96 GNUNET_free (fn);
85 return GNUNET_SYSERR; 97 return GNUNET_SYSERR;
86 } 98 }
87 if (fsize != GNUNET_DISK_fn_read (fn, data, fsize)) 99 ssize = GNUNET_DISK_fn_read (fn,
100 data,
101 fsize);
102 if ( (ssize < 0) ||
103 (fsize != (uint64_t) ssize) )
88 { 104 {
89 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "read", "fn"); 105 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
106 "read",
107 "fn");
90 GNUNET_free (fn); 108 GNUNET_free (fn);
91 GNUNET_free (data); 109 GNUNET_free (data);
92 return GNUNET_SYSERR; 110 return GNUNET_SYSERR;
@@ -95,7 +113,8 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg,
95 pos = 0; 113 pos = 0;
96 while (pos < fsize) 114 while (pos < fsize)
97 { 115 {
98 while ((pos < fsize) && (! isspace ((unsigned char) data[pos]))) 116 while ( (pos < fsize) &&
117 (! isspace ((unsigned char) data[pos])) )
99 pos++; 118 pos++;
100 if (GNUNET_OK != 119 if (GNUNET_OK !=
101 GNUNET_CRYPTO_eddsa_public_key_from_string (&data[start], 120 GNUNET_CRYPTO_eddsa_public_key_from_string (&data[start],