Bug 80378

Summary: Mismatched length of ".pc" extension
Product: pkg-config Reporter: Daniel Macks <dmacks>
Component: srcAssignee: pkg-config
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Use same token for malloc as for string construction

Description Daniel Macks 2014-06-23 07:32:18 UTC
pkg.c scan_dir() has:

#define EXT_LEN 3
[...]
      int len = strlen (dent->d_name);
[...]
          char *pkgname = g_malloc (len - 2);
[...]
	  strncpy (pkgname, dent->d_name, len - EXT_LEN);
          pkgname[len-EXT_LEN] = '\0';

The goal is for pkgname to hold the name without the trailing ".pc" extension (according to the meaning of EXT_LEN as used in the ends_in_dotpc() function). But the malloc is hardcoded as 2. If the extension were to be changed, the number of characters being strncpy'ed would not match the size of the target buffer. Instead, the malloc should use the EXT_LEN token (adjusted for the trailing \0)
Comment 1 Daniel Macks 2014-06-23 07:32:57 UTC
Created attachment 101557 [details] [review]
Use same token for malloc as for string construction
Comment 2 Dan Nicholson 2014-11-12 15:50:06 UTC
Applied in 30437b4. Thanks!

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.