@@ -286,6 +286,18 @@ lua_run_lookup_addr(struct plugin *p, struct srv_ctx *sctx, const void *data,
286286 size_t hostname_len ;
287287 char hostname [DHCP_HOSTNAME_LEN ];
288288 char chaddr [sizeof (((struct bootp * )0 )-> chaddr ) * 3 ];
289+ struct sockaddr_in sin = {
290+ .sin_family = AF_INET ,
291+ #ifdef BSD
292+ .sin_len = sizeof (sin ),
293+ #endif
294+ };
295+ struct sockaddr * sa = (struct sockaddr * )& sin ;
296+ uint32_t ltime = 0 ;
297+ struct iovec iov [] = {
298+ { .iov_base = & ltime , .iov_len = sizeof (ltime ) },
299+ { .iov_base = & sin , .iov_len = sizeof (sin ) },
300+ };
289301
290302 if (len < sizeof (hostname_len )) {
291303 errno = EINVAL ;
@@ -295,31 +307,26 @@ lua_run_lookup_addr(struct plugin *p, struct srv_ctx *sctx, const void *data,
295307 datap += sizeof (hostname_len );
296308 len -= sizeof (hostname_len );
297309
298- if (len < hostname_len ) {
310+ if (hostname_len != 0 ) {
311+ if (len < hostname_len ) {
312+ errno = EINVAL ;
313+ goto out ;
314+ }
315+ memcpy (hostname , datap , hostname_len );
316+ datap += hostname_len ;
317+ len -= hostname_len ;
318+ } else
319+ hostname [0 ] = '\0' ;
320+
321+ if (len < sizeof (* l -> l_req )) {
299322 errno = EINVAL ;
300323 goto out ;
301324 }
302- memcpy (hostname , datap , hostname_len );
303- datap += hostname_len ;
304- len -= hostname_len ;
305-
306325 /* Aligns bootp */
307326 memmove (UNCONST (data ), datap , len );
308327
309328 l -> l_req = data ;
310329 l -> l_reqlen = len ;
311- struct sockaddr_in sin = {
312- .sin_family = AF_INET ,
313- #ifdef BSD
314- .sin_len = sizeof (sin ),
315- #endif
316- };
317- struct sockaddr * sa = (struct sockaddr * )& sin ;
318- uint32_t ltime = 0 ;
319- struct iovec iov [] = {
320- { .iov_base = & ltime , .iov_len = sizeof (ltime ) },
321- { .iov_base = & sin , .iov_len = sizeof (sin ) },
322- };
323330
324331 lua_pop (L , lua_gettop (L ));
325332
0 commit comments