]> git.notmuchmail.org Git - notmuch/blobdiff - lib/xutil.c
Fix double free in guess_from_received_header().
[notmuch] / lib / xutil.c
index 6fa5eb0ddb49dfb12dcd0cf039d4165cd8f6f7cb..268225b8956690137ae471c82e4ef39de71c4a96 100644 (file)
@@ -18,7 +18,6 @@
  * Author: Carl Worth <cworth@cworth.org>
  */
 
-#define _GNU_SOURCE /* For strndup */
 #include "notmuch-private.h"
 
 #include <stdio.h>
@@ -84,11 +83,16 @@ xstrndup (const char *s, size_t n)
 {
     char *ret;
 
-    ret = strndup (s, n);
+    if (strlen (s) <= n)
+       n = strlen (s);
+
+    ret = malloc (n + 1);
     if (ret == NULL) {
        fprintf (stderr, "Out of memory.\n");
        exit (1);
     }
+    memcpy (ret, s, n);
+    ret[n] = '\0';
 
     return ret;
 }