@@ -140,23 +140,19 @@ static int remote_domain_id;
140
140
141
141
static void unlink_qrexec_socket (void )
142
142
{
143
- char socket_address [ 40 ] ;
144
- char link_to_socket_name [ strlen ( remote_domain_name ) + sizeof ( socket_address )] ;
143
+ char * socket_address ;
144
+ char * link_to_socket_name ;
145
145
146
- int v = snprintf (socket_address , sizeof (socket_address ),
147
- "qrexec.%d" , remote_domain_id );
148
- if (v < (int )sizeof ("qrexec.1" ) - 1 || v >= (int )sizeof (socket_address ))
149
- abort ();
150
- v = snprintf (link_to_socket_name , sizeof (link_to_socket_name ),
151
- "qrexec.%s" , remote_domain_name );
152
- if (v < (int )sizeof ("qrexec." ) - 1 || v >= (int )sizeof (link_to_socket_name ))
153
- abort ();
154
- v = unlink (socket_address );
155
- if (v != 0 && !(v == -1 && errno == ENOENT ))
146
+ if (asprintf (& socket_address , "%s/qrexec.%d" , socket_dir , remote_domain_id ) < 0 )
147
+ err (1 , "asprintf" );
148
+ if (unlink (socket_address ) != 0 && errno != ENOENT )
156
149
err (1 , "unlink(%s)" , socket_address );
157
- v = unlink (link_to_socket_name );
158
- if (v != 0 && !(v == -1 && errno == ENOENT ))
150
+ free (socket_address );
151
+ if (asprintf (& link_to_socket_name , "%s/qrexec.%s" , socket_dir , remote_domain_name ) < 0 )
152
+ err (1 , "asprintf" );
153
+ if (unlink (link_to_socket_name ) != 0 && errno != ENOENT )
159
154
err (1 , "unlink(%s)" , link_to_socket_name );
155
+ free (link_to_socket_name );
160
156
}
161
157
162
158
static void handle_vchan_error (const char * op )
@@ -169,18 +165,14 @@ static void handle_vchan_error(const char *op)
169
165
static int create_qrexec_socket (int domid , const char * domname )
170
166
{
171
167
char socket_address [40 ];
172
- char link_to_socket_name [strlen (domname ) + sizeof (socket_address )];
173
- int res ;
174
-
175
- if ((unsigned )snprintf (socket_address , sizeof (socket_address ),
176
- "qrexec.%d" , domid ) >= sizeof (socket_address ))
177
- errx (1 , "socket name too long" );
178
- if ((unsigned )snprintf (link_to_socket_name , sizeof link_to_socket_name ,
179
- "qrexec.%s" , domname ) >= sizeof link_to_socket_name )
180
- errx (1 , "socket link name too long" );
181
- res = unlink (link_to_socket_name );
182
- if (res != 0 && !(res == -1 && errno == ENOENT ))
183
- err (1 , "unlink(%s)" , link_to_socket_name );
168
+ char * link_to_socket_name ;
169
+
170
+ snprintf (socket_address , sizeof (socket_address ),
171
+ "%s/qrexec.%d" , socket_dir , domid );
172
+ if (asprintf (& link_to_socket_name ,
173
+ "%s/qrexec.%s" , socket_dir , domname ) < 0 )
174
+ err (1 , "asprintf" );
175
+ unlink (link_to_socket_name );
184
176
185
177
/* When running as root, make the socket accessible; perms on /var/run/qubes still apply */
186
178
umask (0 );
@@ -189,6 +181,7 @@ static int create_qrexec_socket(int domid, const char *domname)
189
181
}
190
182
int fd = get_server_socket (socket_address );
191
183
umask (0077 );
184
+ free (link_to_socket_name );
192
185
return fd ;
193
186
}
194
187
0 commit comments