@@ -194,6 +194,22 @@ string_hash32(const char *str)
194194 return h ;
195195}
196196
197+ static ssize_t
198+ append_property (char * array , size_t size , ssize_t offset , const char * name , const char * value )
199+ {
200+ int r ;
201+ assert (offset < size );
202+ r = snprintf (array + offset , size - offset , "%s%s" , name , value );
203+ // include the NUL terminator in the string length, as we need to keep it as a separator between keys
204+ ++ r ;
205+ if (r + offset >= size ) {
206+ fprintf (stderr , "ERROR: uevent_sender_send: Property buffer overflow\n" );
207+ abort ();
208+ }
209+
210+ return r ;
211+ }
212+
197213/* this mirrors the code from systemd/src/libudev/libudev-monitor.c,
198214 * udev_monitor_send_device() */
199215void
@@ -206,6 +222,7 @@ uevent_sender_send(uevent_sender * sender, const char *devpath, const char *acti
206222 const char * subsystem ;
207223 const char * devname ;
208224 const char * devtype ;
225+ char seqnumstr [20 ];
209226 struct udev_device * device ;
210227 struct udev_monitor_netlink_header nlh ;
211228 static unsigned long long seqnum = 1 ;
@@ -224,27 +241,15 @@ uevent_sender_send(uevent_sender * sender, const char *devpath, const char *acti
224241
225242 /* build NUL-terminated property array */
226243 count = 0 ;
227- strcpy (props , "ACTION=" );
228- strcat (props , action );
229- count += strlen (props ) + 1 ;
230- strcpy (props + count , "DEVPATH=" );
231- strcat (props + count , udev_device_get_devpath (device ));
232- count += strlen (props + count ) + 1 ;
233- strcpy (props + count , "SUBSYSTEM=" );
234- strcat (props + count , subsystem );
235- count += strlen (props + count ) + 1 ;
236- snprintf (props + count , sizeof (props ) - count , "SEQNUM=%llu" , seqnum ++ );
237- count += strlen (props + count ) + 1 ;
238- if (devname ) {
239- strcpy (props + count , "DEVNAME=" );
240- strcat (props + count , devname );
241- count += strlen (props + count ) + 1 ;
242- }
243- if (devtype ) {
244- strcpy (props + count , "DEVTYPE=" );
245- strcat (props + count , devtype );
246- count += strlen (props + count ) + 1 ;
247- }
244+ count += append_property (props , sizeof (props ), count , "ACTION=" , action );
245+ count += append_property (props , sizeof (props ), count , "DEVPATH=" , udev_device_get_devpath (device ));
246+ count += append_property (props , sizeof (props ), count , "SUBSYSTEM=" , subsystem );
247+ snprintf (seqnumstr , sizeof (seqnumstr ), "%llu" , seqnum ++ );
248+ count += append_property (props , sizeof (props ), count , "SEQNUM=" , seqnumstr );
249+ if (devname )
250+ count += append_property (props , sizeof (props ), count , "DEVNAME=" , devname );
251+ if (devtype )
252+ count += append_property (props , sizeof (props ), count , "DEVTYPE=" , devtype );
248253
249254 /* add versioned header */
250255 memset (& nlh , 0x00 , sizeof (struct udev_monitor_netlink_header ));
0 commit comments